如何实现jquery ajax校验用户名是否存在

2025-01-21 09:33:36
推荐回答(1个)
回答1:

function checkLogin(){
var userType = $('input:radio[name="adminFlag"]:checked').val();
$('#userType').val(userType);
var userId =$("#userId").val();
if (userId.length <= 0||userId==null||''==userId) {
$("#name_error").html("用户名不能为空~");
//$("#tips").window("open").attr("style","height:65px; overflow:hidden;");
flag = false;
return;
} else {
flag = true;
$("#name_error").html("");
}
var url ="<%=PN%>/login_checkUserName.action";
var data = {"userId" : userId,"userType":userType};
$.post(url, data, function(result) {

if (!result ) {
$("#name_error").html("请选择正确的角色或输入正确的用户名~");
//$('#tips').window('open').attr("style","height:65px; overflow:hidden;");
/* $("#userId").val(""); */
flag = false;
return;
} else {
flag = true;
$("#name_error").html("");
}
}, "json");

}