AJAX返回总是ERROR或是没有数据的问题

如果总是到ERROR,是因为async没有定义为false,设置为同步,数据类型要设置为text,不要用json。

示例:

if (IDcard != "")
{
$.ajax({
type: "POST",
dataType: "text",
async:false,
url: "/Ashx/CheckIDCard.ashx",
data: { IDCard: IDcard },
success: function (data) {

if (data == "True") {
$("#cphMain_lbMSG").html("已经存在此身份证号!");
}
else { $("#cphMain_lbMSG").html(""); }
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
alert(result);

}
});
}

原文地址:https://www.cnblogs.com/fbb/p/6439971.html