If I understand correctly, when the handler executes the function you're
defining, you send the result to a JSON Remote (a server). It's most likely
an asynchronous request, so therefore the onComplete isn't going to execute
until the request finishes. You can't get that value and return it like
you're doing now.

You'll need to make the onComplete access the captcha and set its success
itself.

So, again, the onComplete executing last is *expected* behavior.



On Fri, Nov 26, 2010 at 12:21 PM, Rolf -nl <[email protected]> wrote:

> exactly.. create a fiddle and it'll be solved sooner than later :)
>
> On Nov 26, 8:12 pm, אריה גלזר <[email protected]> wrote:
> > please use jsfiddle. mail is hardly a good place for us to read and debug
> > your code
> >
> >
> >
> >
> >
> > On Fri, Nov 26, 2010 at 8:22 PM, machadoug <[email protected]> wrote:
> > > @Oskar,
> > > That's what I had done since the beginning. I just posted that code as
> > > an example.
> > > I've tried the code below but it does not work:
> > > this.setHandler('sicaptcha',
> > >        function (value) {
> > >                var result;
> > >                var url = 'plugins/content/captcha_systems/securImage2/
> > > securimage_json.php';
> > >                var jSonRequest = new Json.Remote(url, {onComplete:
> > > function(response){
> > >                                 if(response.action == 'success'){
> > >                                        return true;
> > >                                }else{
> > >                                         return false;
> > >                                }
> > >                        }
> > >                }).send(Json.toString({'captcha_code':value}));
> > >        }
> > > );
> >
> > > @Andrea,
> > > Yes, the JSON is valid. The same code works in this script:
> >
> > > window.addEvent('domready', function(){
> > >        $('captcha_code').addEvent('blur', function(e) {
> > >                var url = '
> http://localhost/joomla/1.5.12/plugins/content/
> > > captcha_systems/securImage2/securimage_json.php';
> > >                 var log_res = 'si_captcha_log_res';
> > >                $(log_res).addClass('ajax-loading');
> > >                $(log_res).setStyle('display', 'block');
> > >                $(log_res).setHTML('Cheking...');
> >
> > >                var jSonRequest = new Json.Remote(url, {onComplete:
> > > function(response){
> > >                                 //did it return as good, or bad?
> > >                                if(response.action == 'success'){
> > >                                        //email is already in use
> >
> > >  $('captcha_code').removeClass('invalid');
> >
> > >  $('captcha_code').addClass('success');
> > >                                        $(log_res).setHTML('Code is
> > > correct');
> > >                                }else{
> >
> > >  $('captcha_code').removeClass('success');
> >
> > >  $('captcha_code').addClass('invalid');
> > >                                        $(log_res).setHTML('Wrong
> validation
> > > code');
> > >                                }
> > >                                $(log_res).removeClass('ajax-loading');
> > >                        }
> >
> > >  }).send(Json.toString({'captcha_code':$('captcha_code').value}));
> > >        });
> >
> > > });
> >
> > --
> > Arieh Glazer
> > אריה גלזר
> > 052-5348-561
> > 5561
>

Reply via email to