【问题标题】:Redirection after AJAX callback not workingAJAX 回调后重定向不起作用
【发布时间】:2014-10-02 16:57:44
【问题描述】:

我正在使用 jquery ajax 函数调用的 codeigniter 函数代码:

case "Set":

    var message = $('#message').val()
    if ((searchIDs).length > 0) {
        alert("searchIDs " + searchIDs);
        $.ajax({
                type: "POST",
                url: "Ajax/update",
                data: {
                    i: searchIDs,
                    m: message
                },
                dataType: 'json',
                success: function() {
                    alert("OK");
                }
            })
            .done(function() {
                alert("OK");
                location.href = "my_controller/detail";
            });

    } else {
        alert("nothing checked")
    }
    break;

我在 firebug 中或在 firebug 中也看到的被调用 php 函数的响应中没有收到任何错误。但是,我认为 .done 功能不起作用,因为我没有看到 OK 警报并且页面刷新没有发生。

我该如何解决这个问题?

【问题讨论】:

  • 为什么你同时拥有successdone?如果你有后者,你就不需要前者。在 Firebug 中调试时,服务器对 AJAX 请求的响应是什么?该代码似乎没有以任何方式处理错误响应。
  • 你想添加一个error: 参数,你可能没有发现服务器错误。
  • 我正在尝试关注stackoverflow.com/questions/25632701/… 中的第二个答案。我没有ajax经验。大卫,代码工作正常,我在萤火虫中得到“200 OK 120ms”。唯一不起作用的是页面刷新

标签: jquery ajax codeigniter


【解决方案1】:

您是否尝试过 oncomplete 事件处理程序?例如

$.ajax({
   ...
   success: function(){
       ...
   },
   complete: function() {
       //when complete
       ...
   }
})

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-08-15
  • 1970-01-01
  • 2020-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多