Prototype onLoading callback issue

Found out recently (the hard way) that the prototype.js Ajax.Updater onLoading callback is not guaranteed to finish before the Ajax call has completed.

The situation we ran into was pretty standard. An Ajax.Updater call was setup to show a loading image (using onLoading callback), while we awaited response from the server. We also setup the onComplete callback to hide the image. However, when the ajax request was made we were finding that the image was never being hidden.

After doing some research (just reading the prototype documentation) we found that the onLoading callback is not guaranteed. Thus, the onComplete callback was finishing before the onLoading was complete. Apparently, this is documented right in prototype’s ajax documentation … see onLoading callback.

Our solution (reading). While, reading the documentation for the onLoading event we saw the option to use onCreate, which has been available since prototype v1.5.1. This callback runs before the Ajax call is made thus, solving our issue.

That was fun!

No comments yet

Leave a reply