javascript - continue in js program after finishing ajax calls -


i have function 3 ajax calls

var loadeditmodaladdressdata(){      loadcountries();      loadstates();      loaddistricts(); }; 

i want js wait, until ajax calls finished.

part of code

loadeditmodaladdressdata(); $(document).ajaxstop(function(){ // functionality using requested data  .... } 

this worked fine, until added features , figured out $(document).ajaxstop called after every complete request(or bunch of requests),not in function scope, mash code functionality.

how do that?

the dirty way use counter in ajaxstop make sure 3 calls have returned. better way add callbacks each of calls , launch treatment when last received.

however, best way use promises. if use jquery calls, can stuff like:

$.when(call1, call2, call3).then(function(results){      // stuffs }); 

where callx returns $.get (or other jquery promise).

have here.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -