0
  var lng=result.geocodes[0].location.lng;
            var lat=result.geocodes[0].location.lat;
           $.ajax({
                  url:'https://zhihui.farm/markets/'+lng+','+lat+'?limit=2',
                  type:'get',
                  dataType:'json',
                  beforeSend: function(request) {
                    request.setRequestHeader("Authorization", "JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUxYTRjNzg5LTc5ODQtNDE4Mi1iZTFlLWYxYWI0M2E5YzU0MyIsImV4cCI6MTUxNTcyMzQ5My41NTJ9.r131dQYaCYO4hK_vzLLZf6NDhBuiARsyS5sw1H3D2ko");
                  },
                  success:function(data){
                    console.log(data);
                  }, 
                  error : function(errorMsg) {
                    alert("数据请求失败");
                }
              });   
浏览器报的错误:Failed to load https://zhihui.farm/markets/117.251587,39.128291?limit=2: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Ori

gin' header has a value 'http://localhost:3001' that is not equal to the supplied origin. Origin 'http://192.168.11.203:3001' is therefore not allowed access.

怎么解决!?

查看全部 10 个回答

1

服务端无法配置跨域白名单的话,可以使用代理,将其转化为同一个域下,gulp,webpack都有相应的配置