I have this function
function get_last(){
$.ajax({
url:'fronta.php?get_last&last=1',
success:function(data) {
var last = parseInt(data);
}
});
return last;
}
but when I call it like
var last = get_last();
alert(last);
firebug gives me “last is not defined”
How can I pass this last variable into global scope ?
First of all you are calling AJAX asynchrosnously so dont expect you can get the value from ajax response and return it.
Second thing is var last is defined in success handler’s scope so in order to access any variable it should be defined in a proper scope.
If you want you can call ajax sychronously in order to get the response and return it.