是否有可能经过用户导航到该网站的另一个页面,以保持一个AJAX请求有效? [英] Is it possible to keep an AJAX request active after user navigates to another page of the website?
问题描述
我有其中一个用户用ajax提交表单网站。该响应显示在警报的形式是否已成功提交或问题的细节。现在,因为这个过程是异步的,如果用户导航到在接收到响应之前另一页,用于提交表单,该 XMLHtt prequest
对象被删除,并用户不获得关于提交表单的状态反馈。
所以,即使用户导航到另一个页面,才有可能有 XMLHtt prequest
目标保持活跃?
那么,是不是可以有XMLHtt prequest对象保持活动状态,即使用户导航到另一个网页?
没有,不是这样的。该XMLHtt prequest是previous页面的上下文的一部分,并与它一起消失了。
最好的解决办法就是以某种方式prevent用户从导航离开页面,直至请求完成。该 卸载
事件可能在这里派上用场。
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?
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.
这篇关于是否有可能经过用户导航到该网站的另一个页面,以保持一个AJAX请求有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!