jQuery.ajaxSettings.traditional = true
function compareFilesResult(whlIDs) {
var result = 0;
$.ajax({
url: '/ajax/CompareReturnAllResults',
contentType: "application/json; charset=utf-8",
type: 'POST',
dataType: "json",
data: JSON.stringify({ _IDs: whlIDs }),
success: function (data) {
if (data != null) {
compareAllData = data;
return data;
}
},
error: function (data) {
return result;
},
fail: function (data) {
return result;
}
});
}
现在我的Ajax总是被调用,即使结果为NULL,但我想成为NULL,如果它是NULL则再次停止调用它。
答案 0 :(得分:1)
检查它是否为null然后返回如下:
jQuery.ajaxSettings.traditional = true
function compareFilesResult(whlIDs) {
var result = 0;
$.ajax({
url: '/ajax/CompareReturnAllResults',
contentType: "application/json; charset=utf-8",
type: 'POST',
dataType: "json",
data: JSON.stringify({ _IDs: whlIDs }),
success: function (data) {
if (data == null) { /* try also: if (data === null) */
return;
}
if (data != null) {
compareAllData = data;
return data;
}
},
error: function (data) {
return result;
},
fail: function (data) {
return result;
}
});
}