52,795
社区成员




//使用ajax验证用户名是否存在
$("#cateMgr").submit(function () {
if ($.trim($("#cateName").val()) == "") {
$("#msg").html("用户名不能为空!").css("color", "red");
return false;
}
$.ajax({
url: "@Url.Action("CheckCateExists")",
type: "POST",
data: "categoryName=" + $("#cateName").val(),
dataType: "text",
success: function (result) {
if (result == "用户名已经存在") {
$("#msg").html(result).css("color", "red");
return false;
} else {
$("#msg").html(result).css("color", "green");
return true;
}
},
error: function () {
alert("发生错误");
}
});
});
$("#cateMgr").submit(function () {
if ($.trim($("#cateName").val()) == "") {
$("#msg").html("用户名不能为空!").css("color", "red");
return false;
}
var rst = false; ///////////////////////
$.ajax({
url: "@Url.Action("CheckCateExists")",
type: "POST",
data: "categoryName=" + $("#cateName").val(),
dataType: "text",
async: false, ///////////////////////这个最关键
success: function (result) {
if (result == "用户名已经存在") {
$("#msg").html(result).css("color", "red");
} else {
$("#msg").html(result).css("color", "green");
rst = true///////////////////////
}
},
error: function () {
alert("发生错误");
}
});
return rst///////////////////////
});