JS Fetch 仅接受 OPTIONS 请求并将其打印出来
JS Fetch takes only OPTIONS request and print that out
我试图从我的 React 应用程序向我的后端服务器发出请求,前端执行一个 OPTIONS 请求,没关系,问题是我然后在获取控制台上记录了 OPTIONS 响应,而不是真实的在 OPTIONS 请求之后做出的响应。
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
试试这个
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
在 chrome devtools 中检查 "Other" 选项卡。不在 XHR 中
我试图从我的 React 应用程序向我的后端服务器发出请求,前端执行一个 OPTIONS 请求,没关系,问题是我然后在获取控制台上记录了 OPTIONS 响应,而不是真实的在 OPTIONS 请求之后做出的响应。
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => console.log(data));
试试这个
fetch('http://localhost:8080/api/kp/ticket', {
headers: {
"token": sessionStorage.getItem('token')
},
mode: 'cors',
method: 'GET'
}).then(data => (data.json())
.then(res => console.log(res));
在 chrome devtools 中检查 "Other" 选项卡。不在 XHR 中