Is it possible to keep an AJAX request active after user navigates to another page of the website?

本小妞迷上赌 提交于 2019-12-12 01:23:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!