[英]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循环未正确执行。
Below for loop program is executed successfully 以下for循环程序成功执行
<?php for($i=10;$i>1;$i--){ echo "$i<br>"; } ?>
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.