First of all - Thank You very much - it is good lesson.

> To answer your specific question, setting
> a variable who's scope is outside the callback is as easy as defining the
> variable outside the callback:
>
> var foo;
> $.get(..., function() { foo = ...; });

I tried that before:

function test()
{
var ret;
$.get(..., function(data) {  ret= data; });
alert(ret);
}

result:  undefined


> To do what you want, you need to pass a callback to isTracked that will get
> called once the data is available. In your case, you could just pass the
> callback along to $.get. So your setup might look something like:
>
> function isTracked(personcode, callback) {
>   $.get('trackstudent/istracked.php', {'personcode': personcode}, callback);
>
> }
>
> isTracked(code, function(tracked) {
>   // do something with tracked, exactly as you would have done above.
>
> });

That works perfectly!
Now I can do it in my (poor) way, but in other way... (to be honest I
dont know how to do that)
-------
function isTracked(personcode, callback)
{
var ret;
$.get('trackstudent/istracked.php',{'personcode': personcode},
callback);
return ret;
}
...

if (isTracked(personcode, function(data) {
     ret=data;
  })=='true')
{
... //is tracked
}
else
 // isnt tracked
-----
isTracked does not return any value. So how can I get what "$.get"
gets from .php and return from isTracked function? (of course without
adding anything to html as I tried before or without using cookies)

Thanks

Michael

Reply via email to