问题
I am having a website where a user submits a form using ajax. The response is shown in alert whether the form was successfully submitted or the details of the problem. Now since this process is asynchronous, if the user navigates to another page before the response is received, the XMLHttpRequest object that was used for submitting the form is deleted and the user does not get feedback about the status of the submitted form.
So, is it possible to have the XMLHttpRequest object remain active even if the user navigates to another page?
回答1:
So, is it possible to have the XMLHttpRequest object remain active even if the user navigates to another page?
No, it's not. The XMLHttpRequest is part of the previous page's context, and disappears along with it.
The best solution is to somehow prevent the user from navigating away from the page until the request is finished. The unload event might come in handy here.
来源:https://stackoverflow.com/questions/31319889/is-it-possible-to-keep-an-ajax-request-active-after-user-navigates-to-another-pa