前端利用ajax:
var sData = {
email: $("#exampleInputEmail1").val(),
password: $("#exampleInputPassword1").val()
};
$.ajax({
url: "/login",
type: 'post',
dataType: 'json',
contentType : "application/json",
data: JSON.stringify(sData),
success: function(result) {
console.log(result.status);
if (result.status == 1) {
location.href = "/toIndex";
} else {
$("#error2").text("邮箱或密码错误");
}
},
fail:function () {
console.log(111111)
}
});
sData是一个对象,利用JSON.stringify转换为json格式。
具体参数名见下表(来源于菜鸟教程),可以根据自己的需要设置。
名称 | 值/描述 |
---|---|
async | 布尔值,表示请求是否异步处理。默认是 true。 |
beforeSend(xhr) | 发送请求前运行的函数。 |