javascript - Call a function after a bunch of other functions are complete -


so i've got these functions:

function urlexists(url){     $.ajax({       url: url,       success: function(data){         alert('exists');       },        error: function(data){         alert('fail');       }     }); } function addscript(filepath, callback){     if (filepath) {         var fileref = document.createelement('script');         fileref.setattribute("type","text/javascript");         fileref.setattribute("src", filepath);         if (typeof fileref!="undefined")             document.getelementsbytagname("head")[0].appendchild(fileref);     }     if (callback) {         callback();     } } 

and in $(document).ready() i've got bunch of these:

addscript(roofpathmrtu.js); addscript(roofpathtrtu.js); addscript(lowerpathmrtu.js); etc... 

which need check if loaded or not, call:

urlexists('roofpathmrtu.js'); 

the problem urlexists function not working, , think it's because running before addscript functions done.

how can have urlexists function run after addscript functions done? going use callback parameter of addscript function on last one, don't think gonna work.

a way have been doing not use javascript method of setimeout(), using jquery feature when. if not, use que. syntax

$.when(function()).then(fucntion2());  or  $.when(function1()).done(function2()); 

you overlap these if wanted to, not best when considering both elegant , efficiency in code. using que next step, using $.when not accomplish want.

http://api.jquery.com/jquery.when/


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -