Wait after calling a function


How to wait after calling a function? I have this problem when I have to wait for an ajax routine to complete or when I try to obtain IMEI using a phonegap plugin.


I don’t know precisely what you are doing, but generally, something asynchronous will have a Callback function you specify when you make the call. You don’t have to know When that callback will happen, but you will process the next step inside that callback.


The returnFunction is described here:


Also, see this:



Frank and George are both right. In Franks case you use a promise such as .done().
In George’s answer it’s a bit more complicated but it works like this:

function myAjaxFunction()
    return $.ajax();

then in the calling function you can do this…

      var data = myAjaxFunction();
      data = data.responseJSON;
      if(data.status == "OK")


Thank you.
I solved my problem using your suggestions.