Skip to main content

Bug Tracker

Side navigation

#8819 closed bug (invalid)

Opened April 08, 2011 07:57AM UTC

Closed April 19, 2011 07:43AM UTC

Last modified May 07, 2012 08:21PM UTC

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...

Attachments (0)
Change History (4)

Changed April 08, 2011 02:31PM UTC by addyosmani comment:1

owner: → 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.

Changed April 15, 2011 04:56AM UTC by timmywil comment:2

component: unfiledajax

Changed April 19, 2011 07:43AM UTC by jaubourg comment:3

_comment0: 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 request is to avoid at all cost. \ \ In your case, it's not that the browser is frozen before the beforeSend, 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.1303199049424673
_comment1: 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 the beforeSend, 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.1303199111581947
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.