Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax Synchronous Request Failing in Chrome

Tags:

jquery

ajax

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

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

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.

like image 927
Courageous Heart Avatar asked Apr 14 '19 14:04

Courageous Heart


People also ask

Why is AJAX not working chrome?

In the AJAX operation just add: async: false after datatype: "json" , and that should solve your problem. Chrome has issue handling asynchronous calls. Thank you, this resolved my issue. Although oddly, I'd only seen the issue in one specific place.

Can AJAX requests be made synchronous?

AJAX can access the server both synchronously and asynchronously: Synchronously, in which the script stops and waits for the server to send back a reply before continuing. Asynchronously, in which the script allows the page to continue to be processed and handles the reply if and when it arrives.


1 Answers

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 v80 (Feb 2020). Follow the fun in this issue (thank you patmortech for finding that issue).

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.

like image 162
T.J. Crowder Avatar answered Sep 21 '22 14:09

T.J. Crowder