Javascript prototypejs:保留功能直到ajax请求结果出现
我正在使用new to prototype并使用其ajax功能,但无法将值设置为返回类型 我的代码是Javascript prototypejs:保留功能直到ajax请求结果出现,javascript,prototypejs,Javascript,Prototypejs,我正在使用new to prototype并使用其ajax功能,但无法将值设置为返回类型 我的代码是 var captchaRequest = new Ajax.Request('http://www.example.com/captcha/validate.php', { parameters: "captcha_code="+captcha_code, onSuccess: function(result) { if(result.responseText ==
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')
我想做的是在ajax调用完成后执行一些功能,但我的第二个警报是“在ajax之后”,在“在ajax响应中”之前执行。
我想使用ajax响应的代码结果。
请帮忙
谢谢,,
pankaj您不需要将其设置为异步。只需从onsuccess块中调用函数
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')
是的,一个更深思熟虑的答案。你得到了我的投票。实际上,这段代码在一个函数中,我不能在这个块中编写更多的函数。你不是,你是在从这个块调用函数。但它仍然不会等待函数调用它执行下一行代码。现在问题已经解决了,您能告诉我将“异步”设置为trueSynchronous的缺点是什么吗?这意味着在进行ajax调用时整个页面都会暂停。异步meas发生在后台,完成后触发和事件,在本例中为“onSuccess”。我已通过将“Asynchronous”设置为true来解决此问题。现在工作正常,但我想知道使用此方法的缺点是什么。