我有這樣的代碼..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