Ajax调用回不叫。如何解决呢? [英] Ajax call back not called. How to tackle this?

查看:104
本文介绍了Ajax调用回不叫。如何解决呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次来到这里是为您的建议。我有一些AJAX调用从我的编辑是一个PHP在线编辑器运行code。 (你们可以检查我的网站。)

Again I am here for your suggestions. I have some AJAX call for running code from my editor which is a PHP online editor. (You guys can check in my site.)

我有一些Ajax调用的编辑器发送的数据和接收的输出。

I have some ajax call for send the data of editor and received output.

问题:循环执行不正常。

Problem: for loop not executed properly.

  1. 下面的循环程序被成功执行

  1. Below for loop program is executed successfully

<?php
for($i=10;$i>1;$i--){
    echo "$i<br>";
}
?>

  • 虽然这个循环不执行

  • While this for loop is not executed

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

  • 当我运行这个通过萤火,我得到回应说,for循环已成为一个无限循环的情况下,第二环(上图)。

    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).

    现在,这里是我的AJAX回调:

    Now here is my AJAX callback:

    $.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:

    错误:jQuery110106354119750428449_1386321122498不叫

    Error: jQuery110106354119750428449_1386321122498 was not called

    这是我的JSON回调$ C $从服务器C:

    here is my JSON callback code from the server:

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

    请帮我解决这个错误。

    推荐答案

    经过一些测试的,我的事情的问题是 + 的URL,尝试EN code:

    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
    

    服务器得到这个: ($ x = 0; $ X&LT; = 10; $ X) 所以它是无限循环,为$ X保持0

    the server got this: ($x=0; $x<=10; $x ) so it is infinite loop, as $x stays 0

    这篇关于Ajax调用回不叫。如何解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆