Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

ajax - javascript: cancel all kinds of requests

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
  • inserted script-tags (which do JSONP-Communication)
  • 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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...