jquery ajax return没有返回值的解决方法


复制代码 代码如下:

//添加async:false.即修改为同步
//等ajax给bol赋值完毕后,才执行下面的js部分。而异步的话,还没有来得及赋值,就已经return了。
function vcodeYes() {
var bol = false;
$.ajax(
{
type: "GET",
url: "../Ajax/ValidationCode.ashx",
data: { txtVcode: $('#<%=txtVcode.ClientID%>').val() },
async: false,
success: function (data) {
if (data == "0") {
$.dialog({ icon: 'warning', follow: document.getElementById('txtVcode'), content: '验证码错误!' }).time(1);
changeCaptchaImage('imgVerify2', 'txtVcode');
}
else {
bol = true;
}
}
});
return bol;
}
//验证没通过是 返回false 否则执行下面函数
$('.getVodes').click(function () {
if (vcodeYes()) {
。。。执行下面。。。
}
});

作者:曾祥展
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3