为什么不执行成功函数命令

时间:2014-11-02 19:03:16

标签: javascript php jquery ajax codeigniter

enter image description here

我正在使用codeigniter和jquery ajax。我在我的应用程序本地使用wamp(完美运行)和我部署的应用程序(不是那么多)有一些不和。我试图解决这个问题。作为我实验的一部分,我使用以下代码对其进行了修复:'

$.ajax({
    type: "POST",
    url: "Ajax/updateReplies",
    data:{ i : searchIDs, m : message },                        
    dataType: 'json',
    success: function(){
        console.log("hi");
        window.location.href = "controller/reply";
    }

单击该按钮时,我可以在firebug中看到ajax请求有效并且数据已提交到后端codeigniter函数,但是两个成功函数命令都没有执行。

为什么不呢?

1 个答案:

答案 0 :(得分:1)

当您通过属性 dataType 设置ajax请求以接收 json 数据时,您必须确保数据格式正确,否则您将遇到错误。

尝试检查调用是否遇到以下任何问题:

$.ajax({
    type: "POST",
    url: "Ajax/update",
    data:{ i : searchIDs, m : message },                        
    dataType: 'json',
    success: function(){
        console.log("hi");
        window.location.href = "controller/reply";
    },
    //important
    error: function(xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        alert(err.Message);
    }
});

作为最后的手段,我推荐,您可以将 dataType 设置为'text',并避免任何格式问题< / p>