Im trying to set somehow variable inside of $.get callback and get
outside this callback.
Im doing it in this way (because I dont know any other way):

function isTracked(personcode)
{
ret='false';

// it should return string 'true' or 'false'
$.get('trackstudent/istracked.php',{'personcode': personcode},
function(data) {

//because I dont know how to set variable inside of callback and get
outside
if ($('span.tempvar').length==0)
   $('body').append('<span class="tempvar" style="display: none">'+data
+'</span>');
else
    $('span.tempvar').html(data);

// now I should have at the end of <body> a new element <span>
alert('1: '+$('span.tempvar').html());

});
//get variable outside $.get callback
ret=$('span.tempvar').html();
alert('2: '+ret);

//return ret; //ret have proper value
}

.......
when I run this function first time I have two alert messages (data in
$.get is 'true'):
first: "1: true"
second: "2: null"
//second should be: "2: true";

when I run second time I have (data in $.get is 'false'):
first: "1: false"
second: "2: true" //old value! (dont know why!)
//second should be false;

When Im checking genereted by javascript source code I see my <span>

How it is possible?!

or maybe you have another solution how to set variable inside of $.get
callback and get outside

TIA
Michael

Reply via email to