简体   繁体   English

没有调用Ajax回调。 如何解决这个问题?

[英]Ajax call back not called. How to tackle this?

Again I am here for your suggestions. 我再次提出你的建议。 I have some AJAX call for running code from my editor which is a PHP online editor. 我有一些AJAX调用来从我的编辑器运行代码,这是一个PHP在线编辑器。 (You guys can check in my site .) (你们可以在我的网站上查看。)

I have some ajax call for send the data of editor and received output. 我有一些ajax调用发送编辑器的数据和接收输出。

Problem: for loop not executed properly. 问题:for循环未正确执行。

  1. Below for loop program is executed successfully 以下for循环程序成功执行

     <?php for($i=10;$i>1;$i--){ echo "$i<br>"; } ?> 
  2. While this for loop is not executed 虽然这个for循环没有执行

     <?php for ($x=0; $x<=10; $x++) { echo "The number is: $x <br>"; } ?> 

When I run this through FireBug, I get a response saying that the for loop has become an infinite loop in case of second loop (above). 当我通过FireBug运行时,我得到一个响应,说for循环在第二个循环的情况下变成了一个无限循环(上图)。

Now here is my AJAX callback: 现在这是我的AJAX回调:

$.ajax({
    type: 'GET',
    url: 'exec.php',
    data: code,
    success: function(data) 
    {
        alert(data);
        $(loader).addClass("hidden");
        var stdout = $(form).children('.stdout');
        if (data.search("Parse error")>0)
        {
            var str = data.replace("<b>Parse error</b>:  ","");
        $(stdout).html(str);
        $(stdout).removeClass('hidden');    
        }   
        else
        {
            $(stdout).html(data);
            $(stdout).removeClass('hidden');
        }   
    },
    error: function(req, status, err) {
        alert(status);
        alert(err);
    },
    dataType: 'JSONP'
});

I have re-implemented this editor locally and run it; 我在本地重新实现了这个编辑器并运行它; In FireBug I am getting this error: 在FireBug中我收到此错误:

Error: jQuery110106354119750428449_1386321122498 was not called 错误:未调用jQuery110106354119750428449_1386321122498

here is my JSON callback code from the server: 这是来自服务器的我的JSON回调代码:

echo $_GET['callback']."(".json_encode($script_output).");";

Please help me to tackle this error. 请帮我解决这个错误。

在此输入图像描述 After some test's, i thing the problem are the ++ in the url, try to encode: 经过一些测试,我的问题是网址中的++ ,尝试编码:

encodeURIComponent

as this worked for me: 因为这对我有用:

for ($x=0; $x<=10; $x%2B%2B)
  {
  echo "The number is: $x <br>";
  }

... ...

+ = %2B

the server got this: ($x=0; $x<=10; $x ) so it is infinite loop, as $x stays 0 服务器得到这个:($ x = 0; $ x <= 10; $ x)所以它是无限循环,因为$ x保持为0

Replace your code with 替换你的代码

<?php
$opstr = "";
for ($x=0; $x<=10; $x++)
 {
   $opstr .= "The number is: $x <br>";
 }
echo $opstr;
exit();
?> 

And try to execute your ajax call again. 并尝试再次执行您的ajax调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未调用 jQuery Ajax 回调。 解析器错误 - jQuery Ajax callback was not called. ParserError 为什么从未调用$ .ajax()回调函数? - Why $.ajax() call back function are never called? 集中iframe时,不会调用父窗口事件。 怎么预防呢? - When the iframe is focused, the parent window events are not called. How to prevent it? ExtJS和事件侦听器:未调用“加载”。 怎么会? - ExtJS and event listeners : 'load' not called. How comes? 没有调用名为“ clear”的函数。 尝试使用内联js调用“ clear()” - Function named “clear” is not being called. Trying to call “clear()” with inline js 当dataType为JSONP时,未调用ajax成功回调函数。 - ajax success call back function was not called when the dataType is JSONP.in Cross domain Access 我想跟踪并在数据库中保存Java函数被调用的次数。 最好的方法是什么? - I want to track and save in a database how many times a Java function is called. What is the best way to do that? 我正在尝试从onClick事件调用javascript函数,但据我所知该函数没有被调用。 - I'm trying to call a javascript function from the onClick event but as far as I know the function isn't being called. 当前对象中的函数无法调用。 为什么? - Function in current object cannot be called. Why? 如何处理从AJAX调用返回的数组? - How to handle array coming back from an AJAX call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM