Chrome中的Ajax同步请求失败 [英] Ajax Synchronous Request Failing in Chrome

查看:2183
本文介绍了Chrome中的Ajax同步请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome的最新版本是否已停止同步Ajax调用?进行同步Ajax调用时出现错误.我们更新到最新的Chrome版本-73.0.3683.103后,该问题突然出现.目前,同步调用在Firefox和IE上可以正常工作.我们正在遇到错误

Have the latest release of Chrome stopped Synchronous Ajax calls? We are getting the error while doing Synchronous Ajax calls. The issue popped up after we updated to latest Chrome version - 73.0.3683.103. Synchronous calls work fine on Firefox and IE for now. We are getting below error

消息:无法在'XMLHttpRequest'上执行'发送':无法加载'Path ...':页面关闭时同步XHR." 名称:"NetworkError"

message: "Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'Path...': Synchronous XHR in page dismissal." name: "NetworkError"

请问有人可以提出一种解决方案来使Ajax同步呼叫正常工作.我有一些功能需要确定依赖于同步调用.

Can someone please suggest a solution to get Ajax Synchronous calls working. I have some functionality where I need to for sure rely on Synchronous call.

推荐答案

是的,在Chrome中,他们最近不允许在页面结束事件(例如beforeunloadunload)中使用同步ajax.您根本无法再在Chrome中做到这一点. 更新:您可以在v73和v74中再次使用,但是(暂时)计划在v75中再次使用,除非有更多的回退.跟随这个问题的乐趣(感谢您 patmortech 找到该问题).

Yes, in Chrome they just recently disallowed synchronous ajax during end-of-page events (like beforeunload and unload). You simply can't do that anymore in Chrome. Update: You can again, in v73 and v74, but it's slated (for now) to go away again in v75 unless there's more pushback. Follow the fun in this issue (thank you patmortech for finding that issue).

现代的替代方法是使用 sendBeacon ,它使浏览器可以离开页面浏览,同时仍然让您有机会告诉服务器正在发生的事情.这不会阻止页面被解雇.但这只是POST,而且由于它不会阻止页面解雇,因此依赖于阻止页面解雇的用例将无法使用它.

The modern alternative is to use sendBeacon, which lets the browser navigate away from the page while still giving you a chance to tell the server that's what's happening. This doesn't hold up page dismissal. But it's only POST, and since it doesn't hold up page dismissal, use cases relying on holding up page dismissal won't work with it.

这篇关于Chrome中的Ajax同步请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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