开发者

prototypejs : holding functionality till ajax request result come

开发者 https://www.devze.com 2023-01-17 12:25 出处:网络
i am using new to prototype and using its ajax functionality but not abl开发者_运维知识库e to set the values to return type

i am using new to prototype and using its ajax functionality but not abl开发者_运维知识库e 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


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号