jquery - Using $.when to wait for ajax to complete -
i need wait ajax request complete before going on. since request triggered different anchors, wrapped in function. happens after function first ajax has finished, second ajax request.
at first, tried wait first finish using $.ajaxcomplete() ran endless loop because of second ajax request performed thereafter.
i found samples using $.when none of them showed whether it's possible use method instead deferreds.
here's i'd do:
$.when( functionfirstajaxcall(data) ).then( function() { // after first ajax request has finished, following: $.ajax({ //... }); }); does functionfirstajaxcall() need have return value or how can 1 working? way, solution doesn't need use $.when.
update: got working creating custom event vandesh has advised.
function first() { $.ajax({ // ... success: function (d) { $.event.trigger({ type: "finished", data: d }); } }); } $(document).on('finished', second()); anyway, there simple solution using $.when?
yes can! dose work you?
function first() { var = $.ajax({ // ... }); return a.promise(); } first().done(function(){ //im done });
Comments
Post a Comment