ajax - Jquery invoke $.when after a function finished -
i have following code:
ispublisher.done(function(isactive) { if (isactive) { addroletouser(inlineuid, "publisher"); } $.when(setcountryandlanguage(), getuserroles()).done(setinlinemanualtracking); }); //add role inline manual table in db. function addroletouser(userid, role) { return $.ajax({ type: "post", url: "../publisher/service.asmx/addroletouser", data: json.stringify({ id: userid, role: role }), contenttype: "application/json; charset=utf-8", datatype: "json" }); }
i want $.when
occur after addroletouser
function finished. how can achieve that?
i want
$.when
occur afteraddroletouser
function finished.
that's current code does. assuming addroletouser
starts asynchronous process, , want wait until process completes, addroletouser
need accept callback or return promise.
if assume returns promise, can have call $.when
wait resolve (using dummy promise instead if don't call it):
ispublisher.done(function(isactive) { var p; if (isactive) { p = addroletouser(inlineuid, "publisher"); } else { p = $.deferred().resolve().promise(); } p.then(function() { $.when(setcountryandlanguage(), getuserroles()).done(setinlinemanualtracking); }); });
Comments
Post a Comment