javascript - multiple simultaneous ajax requests broker -


how coordinate simultaneous ajax calls , take action when of them completed?

is there convenient javascript helper library coordinate multiple simultaneous ajax calls database , invoke specified callback when of ajax data-fetches have returned data? i'd submit dictionary of primed-and-ready-to-go ajax calls "coordinator" or "broker", along whenallcompleted callback function.

the use case common one: before database record can bound ui, of dropdown lists foreign key data relationships have populated, user sees meaningful values rather integer keys typically stored in record.

i rather not reinvent plumbing code track status of each ajax request if there's robust standard library out there doing already.

edit: here's pseudo-code describes want :

           when ajax1fetch finished            ,            ajax2fetch finished            ,             ajax3fetch finished            , select1 populated            , select2 populated            , select3 populated            bindrecordtoui() 

before restructured code use $.when(), getting data in .ajax() success callback, , populating select right there in callback; when select populated, bind record ui.

if feed $.when list of ajax calls, done callback invoked when ajax requests complete, occurs before selects populated (if list of items select long).

somehow need include population of select elements additional when-conditions, , find way route data returned ajax call populating functions, if select-populate functions not going peformed in .ajax success callback.

you looking promises in js. here nice framework q. , allsettled() function is, looking for.

q.allsettled([savetodisk(), savetocloud()]).spread(function (disk, cloud) {     console.log("saved disk:", disk.state === "fulfilled");     console.log("saved cloud:", cloud.state === "fulfilled"); }).done(); 

code taken api-reference


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -