【问题标题】:Jquery ajax result not working on chromeJquery ajax结果不适用于chrome
【发布时间】:2013-05-13 07:51:26
【问题描述】:

我的 chrome 上的 jquery ajax 有问题。 Ajax 会像这样回显结果:

1||result goes here

这里是 ajax 脚本:

$("#load_cards").click(function() {
        $("#load_cards").fadeOut('fast');
        var form_data = {
            query: 'cardpack',
            page: page,
            pack: pack
        };
        $.ajax({
            type: "POST",
            url: 'ajax.php',
            data: form_data,
            success: function(response)
            {
                response_d = response.split("||");
                response_message = parseInt(response_d[0]);
                response_html = response_d[1];

                if (response_message == 1) {
                    hist = $("#card_pack_list").html();
                    $("#card_pack_list").html(hist+response_html);
                    page = page+1;
                }
                else {

                }
                $("#load_cards").fadeIn('fast');
            }
        });
    });

问题在于 firefox 和 opera 将 response_message 识别为 1,但 chrome 不识别。为什么会这样,我该如何克服?我在 xampp 虚拟服务器上运行脚本。

【问题讨论】:

  • Chrome中response_message的值是多少?
  • 执行console.log(response); 并在 chrome 中检查结果。
  • 如果我将 alert(response_message) 放入代码中,它会在 chrome 中返回 NaNa,在 firefox 中返回 1。
  • 执行 console.log( response ) 并按照 Zim 的说明查看控制台。您没有得到预期的响应。

标签: jquery ajax google-chrome


【解决方案1】:

您确定 Chrome 会进入“成功”回调吗?

如果没有,请尝试在 ajax 调用中添加“完成”和“错误”回调,看看发生了什么:

success: function(response) {
    console.log("success callback");
    ...
},
error: function(jqXHR, textStatus, errorThrown) {
    console.log("error callback : " + textStatus);
},
complete: function(jqXHR, textStatus) {
    console.log("complete callback : " + textStatus);
}

【讨论】:

  • 我认为确实如此,否则 $("#load_cards").fadeIn('fast'); 之后的警报命令不会工作。
  • 这取决于,你的警报到底在哪里?
猜你喜欢
  • 2013-04-22
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
相关资源
最近更新 更多