javascript:取消所有类型的请求

时间:2022-03-01 21:04:29

My website makes a lot of requests. I often need to cancel all current requests, so that the browser is not blocking relevant new requests.

我的网站有很多请求。我经常需要取消所有当前请求,这样浏览器就不会阻塞相关的新请求。

I have 3 kinds of requests:

我有三种要求:

  • Ajax
  • Ajax
  • inserted script-tags (which do JSONP-Communication)
  • 插入的脚本标记(执行jsonp通信)
  • inserted image-tags (which cause the browser to request data from various servers)
  • 插入图像标记(导致浏览器请求来自不同服务器的数据)

For Ajax its no problem as the XMLHttpRequest object supports canceling. What I need is a way to make any browser stop loading resources, from DOM-Objects.

对于Ajax来说,XMLHttpRequest对象支持取消没有问题。我需要的是让任何浏览器停止从dom - object加载资源。

Looks like simply removing an object (eg. an image-tag) from the DOM only helps avoiding an request, if the request is not already running.

看起来简单地删除一个对象(如。如果请求还没有运行,来自DOM的图像标记只会帮助避免请求。

UPDATE: a way to cancel all requests, which are irrelevant, instead of really any request would be perfect.

更新:一种取消所有请求的方法,这些请求是不相关的,而不是任何请求。

2 个解决方案

#1


26  

window.stop() should cancel any pending image or script requests.

stop()应该取消任何挂起的图像或脚本请求。

#2


0  

I think document.close() stops all requests, but I'm not so sure about it.

我认为document.close()可以阻止所有请求,但我对此不是很确定。

#1


26  

window.stop() should cancel any pending image or script requests.

stop()应该取消任何挂起的图像或脚本请求。

#2


0  

I think document.close() stops all requests, but I'm not so sure about it.

我认为document.close()可以阻止所有请求,但我对此不是很确定。