jquery - Using $.when and $.done in AJAX and trying to get result when it is done -
i calling ajax calls , everytime phone call ajax phone call pass function handle it. because keeping counter of ajax requests @ 1 time (mainly using development purposes). trying retrieve results of ajax phone call , set manipulate data.
let me paste code improve clarity.
function get_allsystems() { homecoming $.ajax({ type: "get", url: getsystemurl(), // unimportant, phone call url method cache: false, datatype: "json" }); } // automatically increment , decrement semaphore variable // , execute functions when ajax phone call done. function processajaxcall(performajaxcall, dofunctionwhendone) { ajaxcall++; $.when(performajaxcall).done(function (result) { ajaxcall--; dofunctionwhendone(result); }); } // process ajax scheme info set in object processajaxcall(get_allsystems, function (result) { systemmap["systems"] = result; });
currently getting function result, get_allsystems() instead of actual json of info get.
i want pass ajax calls through function because allows me know if ajax phone call in process , provides level of abstraction like.
so doing wrong, imagine $.done execute when ajax phone call finished , pass results back...but doesn't seem case here.
you need invoke performajaxcall
:
function processajaxcall(performajaxcall, dofunctionwhendone) { ajaxcall++; $.when(performajaxcall()/* phone call function */).done(function (result) { ajaxcall--; dofunctionwhendone(result); }); }
performajaxcall
returns ajax promise object used $.when
.
jquery ajax
No comments:
Post a Comment