axios.post('', {
data: params
},{
headers: {
'Access-Control-Allow-Origin':'*', //解决cors头问题
'Access-Control-Allow-Credentials':'true', //解决session问题
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' //将表单数据传递转化为form-data类型
},
withCredentials : true
})
.then(function (response) {
var res = response.data;
if(res=="登录成功,3秒后跳转主页") {
var noticeId= JSON.parse(window.sessionStorage.getItem('user'));
alert(noticeId)
alert(response.data);
setTimeout(that.LoginSuccess, 3000)
}else if(response.data=="用户名不存在,请注册后重新登录") {
that.message = response.data
}
})
.catch(function (error) {
alert(error);
});
关于axios的post用法
最新推荐文章于 2025-10-13 21:52:23 发布
博客展示了使用axios进行POST请求的代码。设置了请求头以解决CORS头和session问题,将表单数据传递转化为form-data类型。还对响应结果进行了处理,若登录成功则3秒后跳转主页,若用户名不存在则给出提示,请求出错时弹出错误信息。
567

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



