Ajax请求后台数据得到meta: {msg: "无效token", status: 400},代码如下:
function ajRequist() {
var Yu = document.getElementById('yu')
var xhr = new XMLHttpRequest()
xhr.open('get',"http://127.0.0.1:8888/api/private/v1/users",true)
//xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xhr.onreadystatechange = function () {
if (xhr.readyState == 4){
if (xhr.status == 200){
var res = xhr.responseText
res = JSON.parse(res)
Yu.innerHTML = res.meta.msg
console.log(res);
}
}
}
xhr.send(null)
}
请求地址是对的,但是console.log(res)的结果却是meta: {msg: "无效token", status: 400}
请问是需要设置请求拦截吗?
这个问题问后端,无效token,有可能是没登录。有可能是你少携带参数了。也有可能是没有带headers