Is it possible to abort a synchronous XmlHttpRequest?

前端 未结 4 1909
渐次进展
渐次进展 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:50

    You can't:

    http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX sais: "Synchronous AJAX (Really SJAX -- Synchronous Javascript and XML) is modal which means that javascript will stop processing your program until a result has been obtained from the server. While the request is processing, the browser is effectively frozen. The browser treats the call like an alert box or a prompt box only it doesn't wait for input from the user, but on input by the remote server"

    Once the browser runs the sync request, it will wait until it will get a response.

提交回复
热议问题