Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#8819 closed bug (invalid)

jQuery.ajax async:false

Reported by: Moe Owned by: Moe
Priority: undecided Milestone: 1.next
Component: ajax Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Description

If you make an ajax call using the option async:false and beforeSend for example to show a loader, it'l work with FF and Opera but not in IE and Chrome.

Appearantly those two browsers seem to freeze the JS before the beforeSend method is called. However if you alert something either after the showLoader, or in success method, or ignore to hide the loader in complete ... the loader will be visible...

However, if you don't... the loader won't show... no matter how long the request actually take. I have put sleep(4000) in my controller action and the loader is never shown.. i can only see it if I alert something...

Only with async:false...

Change History (4)

comment:1 Changed 9 years ago by addyosmani

Owner: set to Moe
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

comment:2 Changed 9 years ago by timmywil

Component: unfiledajax

comment:3 Changed 9 years ago by jaubourg

Resolution: invalid
Status: pendingclosed

You're right, some browsers will freeze when doing synchronous ajax request. That's why it's been said over and over again that doing synchronous requests is to be avoided at all cost.

In your case, it's not that the browser is frozen before beforeSend is called (lotsa before in there ;)), it's just that the synchronous request prevents the display reflow (which generally happens "sometimes later" than your actual DOM manipulation). I'm pretty confident that, if you try & call showLoader before the call to ajax rather than from inside the beforeSend callback, you'll end up with pretty much the same result.

There is nothing that can be done in jQuery to prevent this behaviour since it is not a jQuery bug (nor a browser one per se, seeing as synchronous xhr requests are supposed to freeze the browser anyway and that nothing says the browser has to carry on with the reflow in that instance).

All I can recommand is to NEVER EVER use synchronous requests. Asynchronous ones are easy enough to deal with.

Last edited 9 years ago by jaubourg (previous) (diff)
Note: See TracTickets for help on using tickets.