我有这样的代码..jQuery的AJAX延迟对象没有返回值
if (!checkIfCustomerIsValid(event)) {
event.preventDefault();
return false;
}
else {
AddCustomer();
}
function checkIfCustomerIsValid(event) {
if ($('#txtCName').val() == '') {
alert('Please enter a valid value for customer name!');
return false;
}
if ($('#txtCAddress').val() == '') {
alert('Please enter a valid value for customer address!');
return false;
}
}
它退回罚款,直到这时,我增加了一个新的检查和它不返回任何东西。
function checkIfCustomerIsValid(event) {
// code that was already there, the name and address check
var _mobNo;
if ($('#txtMobile').val() == '') return false;
var _unq = $.ajax({
url: '../Autocomplete.asmx/IsMobileUnique',
type: 'GET',
contentType: 'application/json; charset=utf8',
dataType: 'JSON',
data: "mobileNo='" + $('#txtMobile').val() + "'",
async: false,
timeout: 2000,
success: function (res) { if (res.d) return false; else return true; },
error: function (res) { alert('some error occurred when checking mobile no'); }
}),chained = _unq.then(function (data) { if (data.d == false) { alert('mobile no already exists!'); $('#txtMobile').focus(); return false; } return true; });
}
如果手机号码是不是唯一的警报显示精细,手机无不是唯一的,但是当它是唯一的代码不会进入AddCustomer
(在其他部分)???它不是真的吗?为什么不进入AddCustomer
???
的[变量不从AJAX函数返回]可能重复(http://stackoverflow.com/questions/12475269/variable-doesnt-get-返回从ajax函数) – 2013-04-05 06:02:12
可能重复的[如何返回来自AJAX调用的响应?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an -ajax-call) – 2014-02-27 13:08:29