How do you make the script wait for the status of an Ajax get request before continuing?

Posted by codeninja on Stack Overflow See other posts from Stack Overflow or by codeninja
Published on 2010-03-12T09:19:41Z Indexed on 2010/03/12 9:27 UTC
Read the original article Hit count: 160

Filed under:
|
|
|

Basically what I'm doing is checking for the existence of an object, if it's not found, the script will try to load the source file using getScript. I only want to check this once though then return true or false to the function that calls fetch()

  fetch:function(obj){
      ...
        isReady = false;
   $.getScript(obj.srcFile,function(){

    isReady=true;
    warn("was able to load object "+key);

   });

   return isReady;

   }

but return kicks in before the script loads =/

later the script is loaded but the function returned false.

This is the beauty of asynchronous I suppose...

What's the best way to handle this... Maybe I could check again at some other point if the object exists?

Or maybe there's a better way to do this where I dont have to potentially lock the browser?

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about jQuery