0

I made a function that runs a get request using JQuery. But I need the get to return this received value to the calling function. function

gettime() {

var timeOut =0;


    $.get("http://localhost:8080/t.html", function( data )
         {

               timeOut = data*1000;
               return timeOut;
         });


    //retun(timeOut);
 }

I want the value received by get to be returned to the main function that calls gettime() please help out. It's a integer am passing.

BMC
  • 591
  • 3
  • 7
  • 22

1 Answers1

1

An idea could be implementing a callback:

function gettime(callback) {
    var timeOut =0;

    $.get("http://localhost:8080/t.html", function(data)
    {
        timeOut = data*1000;
        callback(timeOut);
    });
}

//Then you can retrieve that value by doing this:

gettime(function(timeout){
    //Do your stuff here.
});
Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45