报错:
Failed to load http://10.94.20.20:8080/youqu_interface/BZK/information/getByJunrenId.do?id=1:
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*'
when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not
allowed access.
解决方法:将credentials: 'include'注释。
正确请求示例:
var url=port + '/BZK/information/getByJunrenId.do?id=1';
fetch(url,{
method:'GET',
// mode:'cors',// 避免cors攻击
// credentials: 'include'
}).then(function(response) {
//打印返回的json数据
response.json().then(function(data){
console.log(data);
});
}).catch(function(e) {
console.log("Oops, error");
});
response.json()是promise,.then来拿数据
参考链接
网友评论