ajax 和 axios 添加请求头
ajax 和 axios 添加请求头的方法
·
1、ajax 添加请求头
$.ajax({
url: url,
type:"post",
dataType:"json",
data:data,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("authorization", "authorization");
XMLHttpRequest.setRequestHeader("timestamp", new Date().getTime());
},
success:function (data) {
},
error:function (data) {
}
})
2、axios 添加请求头
this.$axios.post(url, data,
{
headers: {
'authorization': 'authorization',
'timestamp': new Date()
}
})
.then(res => {
})
service.interceptors.request.use(
config => {
config.headers.common['timestamp'] = times;
config.headers.common['authorization'] = 'authorization'
return config
},
error => {
return Promise.reject(error)
}
)
更多推荐
已为社区贡献1条内容
所有评论(0)