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:

    var r;
    
    function isTracked(personcode, callback) {
        $.get('trackstudent/istracked.php',{'personcode': personcode}, 
callback);
    }
    
    $(document).ready(function() {

        isTracked('10591891',function(data) {
            r=data;
            alert(r);
        });
    
    });

If that doesn't quite make sense, sprinkle the code with console.log() 
statements, run it in Firefox with Firebug enabled, and watch
the console to see the order of execution.

-Mike

> -----Original Message-----
> From: jquery-en@googlegroups.com 
> [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
> Sent: Thursday, September 27, 2007 7:01 AM
> To: jQuery (English)
> Subject: [jQuery] Re: functions after $.get work strange
> 
> 
> > 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.
> >
> > });
> 
> I thought that I understand that but Im doing something wrong.
> (istracked.php has 'true' or 'false')
> -------
> var r;
> 
> function isTracked(personcode, callback) {
>       $.get('trackstudent/istracked.php',{'personcode': 
> personcode}, callback);
>       return r;
> }
> 
> $(document).ready(function() {
> 
> alert(isTracked('10591891',function(data) {
>       r=data;
> }));
> 
> });
> ----
> istracked.php returns 'true'
> result of alert:    undefined
> should be:   true
> 
> Callback is still running last .
> I have no idea for that :/
> 
> TIA
> 
> Michael
> 

Reply via email to