在提交表单后,Chrome似乎没有触发javascript xmlhttprequests,但是FF和IE可以 [英] Chrome doesn't seem to fire javascript xmlhttprequests after a form submit, but FF and IE do

查看:67
本文介绍了在提交表单后,Chrome似乎没有触发javascript xmlhttprequests,但是FF和IE可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下一页加载时,我使用这个小技巧来更新当前页面. 当用户单击提交"时,我设置了一个间隔计时器,该计时器会xhr调用服务器以找出响应将花费多长时间,并使用此信息更新页面,从而成功地使用户娱乐.

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.

在Firefox和IE中,此方法工作正常,但在表单提交发生后在chrome中看来,setinterval调用仍会触发,但xmlhttprequest从未实际执行该请求.我没有任何错误或异常,只是做到了

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);

我的statstatechange函数永远不会被调用,并且在服务器端也看不到任何请求,据我所知,永远不会发出请求.

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.

有什么想法让chrome做到这一点吗?

Any idea how to make chrome do this?

推荐答案

对于任何在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.

这篇关于在提交表单后,Chrome似乎没有触发javascript xmlhttprequests,但是FF和IE可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆