views:

16

answers:

1

i am using new to prototype and using its ajax functionality but not able to set the values to return type my code is

var captchaRequest = new Ajax.Request('http://www.example.com/captcha/validate.php', {
       parameters: "captcha_code="+captcha_code,
   onSuccess: function(result) {

    if(result.responseText == 'true') {
     return true;
    } else {
     return false;
    }
                 alert('in ajax response');

       }
});
alert('after ajax')

what i want to do is execute some functionality after ajax call is complete and but my second alert which is 'after ajax' is getting executed before 'in ajax response'. I want to use code result from ajax response. please help.

Thank you, pankaj

+1  A: 

You do not need to set it to async. Just call your function from within the onsuccess block.

  var captchaRequest = new Ajax.Request('http://www.example.com/captcha/validate.php', {
               parameters: "captcha_code="+captcha_code,
           onSuccess: function(result) {

        if(result.responseText == 'true') {
         **callMyFunction()**
         return true;
        } else {
         return false;
        }
                     alert('in ajax response');

           }
    });
    alert('after ajax')
Diodeus
Yeah, a much more thought out answer. You get a vote up from me.
Anders
actually this code is in one function and i can't write more functions in this block.
PankajK
You're not, you're CALLING a function from this block.
Diodeus
but still it will not wait for function call it executes next line of code. it has been solved now, can you tell me what is a drawback of setting "asynchronous" to true
PankajK
Synchronous means your entire page pauses while the ajax call is being made. Asynchronous meas is happen in the background and fire and event when complete, in this case "onSuccess".
Diodeus