IE浏览器替代window.stop()(取消所有待处理的请求) [英] IE alternative to window.stop() (cancel all pending requests)

查看:581
本文介绍了IE浏览器替代window.stop()(取消所有待处理的请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个替代window.stop()的IE浏览器。我曾尝试document.execCommand(停止),但它似乎并没有工作。我想取消它是从我使用ASP的用户控件中称为XMLHtt prequest。我不能使用jQuery的.abort(),因为我没有设置要求我自己。

I'm looking for an alternative to window.stop() for IE. I have tried document.execCommand('Stop'), but it doesn't seem to work. I'm trying to cancel a XMLHttpRequest which is called from within a ASP user control i'm using. I can't use jQuery's .abort() since i do not set the request my self.

推荐答案

我想在页面上控制使用jQuery.ajax,你知道,当你需要中止请求,根据您的标准。

I assume control on the page uses jQuery.ajax and you know when you need to abort the request, under your criteria.

怎么这样呢?

(function ($) {
    var xhr = null, 
        originalAjax = $.ajax,
        updatedAjax = function (url, options) {
            xhr = originalAjax(url, options);
        };
    $.ajax = updatedAjax;
})(jQuery);

现在你有一个变量叫做XHR持有标的XMLHTTP对象。当你需要,你可以拨打中止()的对象。

Now you have a variable called xhr which holds the underlying xmlhttp object. You can call abort() on the object when you need to.

在画背面是该变量将被填充每个Ajax请求的jQuery做的,我只包括特定页面上的这个脚本,甚至重置AJAX当你完成。

The draw back is that variable will be populated for each ajax request done by jQuery, and I would only include this script on that particular page, maybe even reset the ajax when you are done.

我没试过,只是一个想法,因为我一直在嘲弄Ajax调用所有的时间。或许有人会认为,这种做法是有点激烈!

I haven't tried this, just an idea, as I have been mocking ajax calls all the time. Some might think that this approach is a little bit drastic!

希望你觉得它有用。

这篇关于IE浏览器替代window.stop()(取消所有待处理的请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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