JQuery AJAX beforeSend Error

Today I have came by a very strange behavior that was blocking up a dialog to show just prior to the ajax to load. The ajax was binded to a click event and on the ajax beforeSend I had:


In theory the beforeSend event will be triggered every time for the ajax call, but, if you have async: false in the ajax call, this will never work for Chrome and IE. Reason is that the beforeSend for both Chrome and IE happens after the ajax is completely done and at that point, my  afterSend took over and closed the dialog.

Off course changing it to async: true will make the dialog to open immediately, but it is not on every ajax request that you want to make it async: true. Take for example when you really want block everything else until the element is fully loaded.

Anyway, there are several ways to solve the issue but if async:true works for you, that is all you need to do.

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: