后端返回token怎么放到请求头里面,求指教
$("#register_button").click(function () {
if($("#verifyId").val().length>0&&$("#register_phone").val().length>0&&$("#register_password").val().length>0){
let param_array = $("#register_form").serializeArray();
let json = {};
for (i in param_array) {
json[param_array[i].name] = param_array[i].value;
}
const json_str = JSON.stringify(json);
alert(json_str);
$.ajax({
url: '${pageContext.request.contextPath}/user/register?t='+new Date().getTime()+ '&verify_code=' + json.verify_code,
type: "POST",
data: json_str,
contentType: "application/json",
// dataType: "json",
success: function (results) {//请求成功的回调函数
if(results.success==true){
console.log(results.message);
// localStorage.token=results.message;/持久性存储
sessionStorage.setItem('token',results.message);//会话存储
//跳转到首页
$(window).attr("location","${pageContext.request.contextPath}/jsp/home_page.html");
}else{
alert(results.success);
}
},
error: function (results) {//请求失败的回调函数
alert("请求失败!!!");
}
});
}else{
alert("请填写完整的登录信息!!!");
}
});