As I said to you offlist, it doesn't work that way. The value from $.get CAN NOT be returned from isTracked because isTracked will have returned before the $.get callback executes. Instead of:
if(isTracked(code) == 'true') { // thing A } else { //thing B } You have to do: isTracked(code, function(tracked) { if(tracked == 'true') { // thing A } else { //thing B } }); In JavaScript, there's only 1 thread of execution. There's no multithreading, and no "waiting". If you want something to run, that isn't ready to run right now, you have to use some sort of callback that can get run when it is ready. --Erik On 9/27/07, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: > > > > Michael Geary wrote: > > You're still expecting things to happen in the wrong order. It's *inside > the callback* that the data becomes available, and this is > > long after isTracked() returns. Try this instead: > > Yes, but I want have a function that will return what i get from > istracked.php > to use it like that: > > function isTracked(...) > { > $.get('istracked.php',...); > return value_from_istrackedphp > } > //and then > > if (isTracked(...)=='true') > //thing A > else > //thing B > > --- > > var r; > > > > function isTracked(personcode, callback) { > > $.get('trackstudent/istracked.php',{'personcode': personcode}, > callback); > > } > > > > $(document).ready(function() { > > > > isTracked('10591891',function(data) { > > r=data; > > alert(r); > > }); > > > > }); > So in that case I dont have to use callback in isTracked. > I can do the same thing in this way: > function isTracked(personcode) { > $.get('trackstudent/istracked.php',{'personcode': personcode}, > function(data) { > r=data; > alert(r); > }); > } > > and i still will have alert with proper value, but its not what I > want. > I want to get data from php file and return it from isTracked > function. ( to do something like that: ... > if (isTrackes(..)=='true')) > > > Thanks > Michael > >