javascript - Check whether all rest requests got response or not in backbone js -
i want callback function called after rest requests got response server in backbone js. function execute after requests got response, not each response.
i know success, error, , complete methods but, these methods executes each response.
please tell me other functions present or called after response received server.
i posted code below fetch data server.
fetchnextpage : function( successcallback, errorcallback, completecallback, context ) { this.requestnextpage({ remove : false, success : function( collection, response, options ) { if ( typeof successcallback === "function" ) { successcallback.apply( context, [ collection, response, options ]); } }, error : function( collection, response, options ) { if ( typeof errorcallback === "function" ) { errorcallback.apply( context, [ collection, response, options ]); } }, complete: function( xhr, status ){ if ( typeof completecallback === "function" ) { completecallback.apply( context, [ xhr, status ]); } } }); }
you want jquery $.when()
function.
jquery.when( deferreds )
provides way execute callback functions based on 1 or more objects, deferred objects represent asynchronous events.
each jquery ajax request return jqxhr object part of jquery's implementation of promises. jqxhr object returned synchronously, , triggers again when asynchronous operation represents completes. can set listener/callback on 1 (or more) of promises $.when(). value returned asynchronous operation passed callback wrapped then
.
$.when(jqxhr1, jqxhr2, jqxhr3).then(function(return1, return2, return3) { //callback here run after requests returned //asyncronous operations linked jqxhr 1-3 completed. });
Comments
Post a Comment