So, your app only uses a certain version of jQuery from last year sometime, e.g. v 1.4.2
Not a problem, you can add in the newer features you need by copying form the source and defining any dependencies used by the newer code, also copied from the source. Use the Source, Luke
This example shows how to add $.Deferred and the jQuery promise methods to your app which is still using version 1.4.2; perhaps some mission critical plugin or other code is preventing you from an upgrade to the lasted jQuery release.
Links on the topic of Deferreds / Promises
- http://api.jquery.com/jQuery.ajax/
- http://msdn.microsoft.com/en-us/scriptjunkie/gg723713
- http://quickleft.com/blog/jquery-15-hotness-part-2 | https://gist.github.com/862567
- http://joseoncode.com/2011/09/26/a-walkthrough-jquery-deferred-and-promise/
Short explanation
- You really want to use jQuery methods : $.Deferred() .promise() .done() .fail() .isResolved() .isRejected() .then() .always() .pipe() .when()
- You may be using a service to get some data e.g. via .ajax()
- You need both ajax actions to complete (with success) then your code responds after both actions are done.
- See Gists below … https://gist.github.com/1273143 | https://gist.github.com/1273133
See working example at : http://pixelhandler.com/downloads/code/deferred-promise/