Chrome 似乎不会在表单提交后触发 javascript xmlhttprequests,但 FF 和 IE 会
我使用这个小技巧在加载下一页时更新当前页面。 当用户单击“提交”时,我设置了一个间隔计时器,该计时器对服务器进行 xhr 调用,以了解响应需要多长时间,并使用此信息更新页面,从而成功地娱乐用户。
在 Firefox 和 IE 中,这工作正常,但在 chrome 中,表单提交发生后,setinterval 调用仍然会触发,但 xmlhttprequest 从未真正执行请求。我没有收到任何错误或异常,它只是执行此操作
xmlhttp.onreadystatechange = statstatechange;
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(postdata);
,并且我的 statstatechange 函数永远不会被调用,而且我在服务器端没有看到任何请求,据我所知,该请求永远不会被发出。
知道如何让 chrome 做到这一点吗?
I use this little trick to update the current page while the next page is loading.
When the user clicks submit, I set an interval timer which does xhr calls to the server to find out how much longer the response is going to take and update the page with this information, thus successfully entertaining the user.
In Firefox and IE this works fine, but it seems in chrome after the form submit happens, the setinterval call will still fire but the xmlhttprequest never actually performs the request. I don't get any errors or exceptions, it just does this
xmlhttp.onreadystatechange = statstatechange;
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(postdata);
and my statstatechange function never gets called, and I see no requests on the server side, so as far as I can tell the request never gets made.
Any idea how to make chrome do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于在 chrome 中遇到相同问题的任何人:事实证明,如果页面上有 iframe,则可以在该 iframe 中触发 xhr 请求,即使在提交主顶级页面表单后,它们也将继续工作。所以这是一个蹩脚的解决方法,但至少它有效。
For anybody having the same problem in chrome: it turns out that if you have an iframe on the page, you can fire xhr requests in that iframe and they will continue to work even after the main top level page form has been submitted. So it's a crappy workaround but at least it functions.
尝试添加这两个
try adding these two