$.ajax({
url : "http://localhost:8080/user/login", //请求地址
dataType : "json", //返回数据格式
async : true , //是不是异步请求 默认异步
data : {username:username,password:password}, //参数传递
type : "post", //请求方式
success:function (res){
// 请i去成功时的操作
console.log(res);
if (res.code ==10000){
//登陆成功 跳转index
window.location.href="index.html";
}else {
//登陆失败
$("#tips").html("<label style='color:#c687da'>"+res.msg+"</label>");
}
}
}
)
Ajax基本格式
最新推荐文章于 2023-08-02 22:26:34 发布
这段代码展示了如何使用Ajax进行异步登录请求。它向`http://localhost:8080/user/login`发送POST请求,携带用户名和密码数据。如果服务器返回的响应码为10000,表示登录成功,会将页面重定向到`index.html`;否则,会在页面上显示错误消息。
1043

被折叠的 条评论
为什么被折叠?



