美文网首页
Fetch相关

Fetch相关

作者: Ysj1111 | 来源:发表于2017-11-23 14:31 被阅读6次

报错:

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来拿数据
参考链接

相关文章

网友评论

      本文标题:Fetch相关

      本文链接:https://www.haomeiwen.com/subject/igszvxtx.html