I'm not quite understanding you, but it seems like you need to just pass
along callback functions? Maybe you want something like:

function checkRegistered(email, doIfRegistered, doIfNotRegistered) {
        var url='http://localhost/coudou/check/register.php?email=' + email;
        $.getJSON(url, function(res){
               if(res.registed){
                       doIfRegistered();
               }else{
                       doIfNotRegistered();
               }
       });
}

Then you use it like:

checkRegistered('[EMAIL PROTECTED]', function() {
    alert('Alice is registered');
}, function () {
    alert('Alice is not registered.');
});

You have to use callbacks when you're dealing with asynchronous events.

Hope it helps.

--Erik


On Thu, Nov 13, 2008 at 8:17 PM, Freshow <[EMAIL PROTECTED]> wrote:

>
> Yes, it work
>
> but I want define the total as a function be called by different var
> url, and do different actions judge by true or false returned, any way
> can realize it ?
>
> On 11月14日, 上午1时41分, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> > The $.getJSON callback function is not called at the time you make the
> > $.getJSON call. It's called asynchronously, much later, after the data
> has
> > been downloaded. The return value from the callback is discarded -
> there's
> > no one to return it to.
> >
> > Did you want to take two different actions depending on the value of
> > res.registed? Then do it right there in the callback. For example:
> >
> >         $.getJSON(url, function(res){
> >                 if(res.registed){
> >                         doOneThing();
> >                 }else{
> >                         doAnotherThing();
> >                 }
> >         });
> >
> > -Mike
> >
> > > -----Original Message-----
> > > From: jquery-en@googlegroups.com
> > > [mailto:[EMAIL PROTECTED] On Behalf Of Freshow
> > > Sent: Thursday, November 13, 2008 7:58 AM
> > > To: jQuery (English)
> > > Subject: [jQuery] How can I return some value in jquery's
> > > callback function?
> >
> > > it didn't work when I 'return true' or 'return false', is
> > > there some way to get it?
> > > ==============================================================
> > > var 
> > > url='http://localhost/coudou/check/register.php?email='+<http://localhost/coudou/check/register.php?email=%27+>str;
> > >    $.getJSON(url, function(res){
> > >            if(res.registed){
> > >                    return true;  // not work
> > >            }else{
> > >                    return false; // not work
> > >            }
> > >    });
>

Reply via email to