In my ZenDesk app, I:
- retrieve some identifying information from the ticket and requester
- make several requests to another web service
- modify the ticket with the combined results
Using plain jQuery, you'd coordinate this using jQuery.when(deferreds) to trigger step 3 once all of the requests in step 2 are complete:
$.when($.ajax("/page1"), $.ajax("/page2"))
.done(function(page1result, page2result) {
// modify the ticket with the results
});
- Is jQuery.when() available in an App? (I tried
this.$.when()with no luck.) - If not, what's the preferred way to accomplish something similar? (Perhaps using Promises directly?)
jQuery.when()is available through the application object asthis.when(). Here's a simple example (framework version 0.5) that creates a couple trivial promises (usingthis.promise(), similar tojQuery.Deferred()) then waits until they have succeeded/resolved to invoke a third function.Substitute
this.ajax(...)forthis.createPromise()to do real work.app.js