简体   繁体   English

为什么ajaxStop()没有在Internet Explorer中触发?

[英]Why is ajaxStop() not firing in Internet Explorer?

this is my first time using ajax. 这是我第一次使用ajax。 and i don't have an idea where the ajaxStop takes place. 我不知道ajaxStop发生在哪里。 I am using the ajaxStart to show a loading image and need the ajaxStop to hide the loading image. 我使用ajaxStart来显示加载图像,需要ajaxStop来隐藏加载图像。 Please help. 请帮忙。

I have this code to call a popup from "PageOne" 我有这个代码从“PageOne”调用弹出窗口

function ShowFixSteps(path, title){
  var winHeight = parseInt(jQuery(window).height() - 100);
  var winWidth = parseInt(jQuery(window).width() - 600);

  jQuery.ajax({
    url: path,
    success: function(data) {
      jQuery("#divPopup").load(path).dialog({
        modal: true,
        width: winWidth,
        height: winHeight,
        title: title,
        position: "center"
      });
    }
  });

  jQuery("#divPopup").bind("dialogbeforeclose", function(){
    jQuery("#divPopup").empty('');
  });
}

And on my Master page, I have this code to check the start and stop of ajax call: 在我的母版页面上,我有这个代码来检查ajax调用的开始和停止:

$(document).ajaxStart(function() {
  alert('start');
});

$(document).ajaxStop(function() {
  alert('stop');
});

$(document).ajaxError(function() {
  alert('error');
});

It alerts the START but not the STOP: no ERROR also. 它会警告START但不会发出STOP:也没有错误。

NOTE: START and STOP alerts are working on Chrome but not IE. 注意:START和STOP警报适用于Chrome,但不适用于IE。

ajaxStop is triggered after all current AJAX requests have completed. 在所有当前的AJAX请求完成后触发ajaxStop

You can read more about ajaxStop using the jQuery API documentation. 您可以使用jQuery API文档阅读有关ajaxStop更多信息

You can use .ajaxStop() in the following manner: 您可以通过以下方式使用.ajaxStop()

$(document).ajaxStop(function() {
    $('#loading-spinner').hide();
});

Or you could add :complete callback to your AJAX function, like so: 或者您可以添加:complete对AJAX函数的回调,如下所示:

jQuery.ajax({
    url: path,
    success: function(data) {
      jQuery("#divPopup").load(path).dialog({
        modal: true,
        width: winWidth,
        height: winHeight,
        title: title,
        position: "center"
      });
    },
    complete: function() {
        // do something here when ajax stops
        // like hiding the spinner or calling another function
    }
  });

And as you mentioned how to stop an AJAX request in one of your comments, here's how: 当你提到如何在你的一条评论中停止一个AJAX请求时,方法如下:

var ajax1 = $.ajax({
    type: "POST",
    url: "some.php",
    ...
});

ajax1.abort()

You could check if a specific AJAX request is running before aborting by doing this: 您可以通过执行以下操作来检查在中止之前是否正在运行特定的AJAX请求:

if (ajax1) {
    ajax1.abort();
}

Or you could check to see if any ajax requests are running before aborting by doing something like this: 或者您可以通过执行以下操作来检查是否有任何 ajax请求在中止之前运行:

var ajax_inprocess = false;
$(document).ajaxStart(function() {
    ajax_inprocess = true;
});
$(document).ajaxStop(function() {
    ajax_inprocess = false;
});

if (ajax_inprocess == true) {
    request.abort();
}

Beware using .abort() though, as it only stops the client-side code from listening for a response, it wont actually stop the server from working. 请注意使用.abort() ,因为它只会阻止客户端代码侦听响应,它实际上不会阻止服务器工作。 There are actually a few major caveats using this, so make sure you read about it first. 实际上有一些主要的注意事项,所以请务必先阅读。

UPDATED ANSWER FOR UPDATED QUESTION 对更新问题的更新答案

For IE problem, try using: 对于IE问题,请尝试使用:

$(document).ajaxComplete(function() {
    // do something
})

Instead of ajaxStop() . 而不是ajaxStop() ajaxComplete() will fire each time an AJAX request finishes, rather than when ALL requests have finished using ajaxStop() . ajaxComplete()将在每次AJAX请求完成时触发,而不是在所有请求都使用ajaxStop()完成时ajaxStop() Maybe it will help, maybe not. 也许它会有所帮助,也许不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM