Is it possible to abort a synchronous XmlHttpRequest?

前端 未结 4 1864
渐次进展
渐次进展 2021-01-19 01:35

I have written a JavaScript function that asynchronously calls a web service using XmlHttpRequest. I have been asked to make this function finish its work before the page is

4条回答
  •  爱一瞬间的悲伤
    2021-01-19 01:42

    XMLHttpRequest support abort method, you can get more details about it here: http://www.w3.org/TR/XMLHttpRequest/#the-abort-method

    But you need to check how many browserы support it. For example, abort was introduced in Windows Internet Explorer 7 and above.

    Before or after calling send() method of XMLHttpRequest object you can setup a timer for n-seconds delay which will interrupt an asynchronous operation which is in progress.

提交回复
热议问题