Wait after calling a function


#1

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.


#2

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.


#3

The returnFunction is described here:

https://wiki.appstudio.dev/Ajax

Also, see this:

https://wiki.appstudio.dev/Ajax_made_Simple#Asynchronous_Calls


#4

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.done();
      
      data = data.responseJSON;
      if(data.status == "OK")
      {
      }

#5

Thank you.
I solved my problem using your suggestions.

Regards.