; (function ($) {
$(document).ready(function () {
$("form").submit(function () {
var flag = true;
//验证账号密码
//获取用户信息框
var $account = $("input[name=account]");
var $password = $("input[name=password]");
var userData = {
account: $account[0].value,
password: $password[0].value
};
//清空验证信息
if (userData.account == "") {
flag = false;
swal({
title: "提示",
text: "请输入账号"
});
}
if (userData.password == "") {
flag = false;
swal({
title: "提示",
text: "密码不能为空"
});
}
if (userData.password != "" && userData.account != "") {
$.ajax({
type: "POST",
url: "/api/User/Login",
data: { "account": userData.account, "psd": userData.password },
dataType: "json",
error: function (data) {
flag = false;
alert("登录错误,请于管理员联系");
},
success: function (data) {
if (data.code == 4) {
flag = false;
alert(data.errorMsg);
}
if (data.code == 2) {
flag = false;
alert(data.errorMsg);
}
}
});
}
aler(flag); //这里不管ajax里面怎么判断,这里都是true
return flag;
});
});
})(jQuery);