0

I have a function called "myCall()" like this:

function myCall() {

    $.ajax({
        type: 'get',
        url: 'file.php?id=10',
        dataType: 'json',
        cache: false,       
        success: function(data) {
            return data;
        },
        error: function(data) {
            alert('error!');
        }
    });

}

As you can see, this funcion call the "file.php?id=10" and get a return.

That's ok.

But here is my localFunction():

function localFunction() {
    show = myCall();
    alert(show);
}

As you can see, the localFunction() alert shows "undefined".

How can I make the show = myCall() wait the response before go to next code line?

Fiddle:

Russel Riehle
  • 267
  • 1
  • 11

0 Answers0