see the example first then you can understand my question.
var x;
function checkTime() {
$.ajax({
type: 'GET',
url: 'http://www.example.com/time.php',
data: test,
dataType:'json',
success: function (data) {
if (data == 0){
x = 'true';
} else if (data == 1){
x = 'false';
}
}
});
}
checkTime();
alert (x);
the alert will be undefined
I need to set x inside the checkTime functions and grab it outside the function
even if i do :
var x = checkTime();
alert (x);
i still get undefined
also i only need to check for true or false, maybe there is another way to do things. I also tried:
...
if (data == 0){
return true;
} else if (data == 1){
return false;
}
...
but i don't know how to check for that.
basically i need to so something like :
if (x == 1){ // if(x == true) //do something }
any ideas?
thanks