function login() {
var url = PREFIX_URL + "index.php?c=user&a=login";
var loginEmail = document.getElementById("loginEmail");
var loginPassword = document.getElementById("loginPassword");
if ($.trim(loginEmail.value) != "" && $.trim(loginPassword.value) != "") {
var postData = "username=" + loginEmail.value + "&password=" + loginPassword.value +
"&rememberMe=";
$.ajax(url, {
type: 'post',
data: postData,
headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
success: function (data) {
if (typeof data == "object") {
if (data.code == 1003) {
$('#loginError').css({display: "block"});
$('#loginError').text(data.msg);
}
return
}
var jsonData = eval("(" + data + ")");
switch (jsonData.code) {
case 200 :
$('#loginModal').modal('hide');
window.location.href=PREFIX_URL +"index.php/#/main";
break;
case 1004:
$('#loginError').css({display: "block"});
$('#loginError').text(jsonData.msg);
break;
}
}
});
} else {
if ($.trim(loginEmail.value) === "") {
$('#loginError').css({display: "block"});
$('#loginError').text("邮箱不能为空");
} else {
$('#loginError').text("密码不能为空");
}
}
}
这是js登录实现
qq_青枣工作室_0