Jquery 如何从我的reactjs组件发出跨域请求?
我有一个reactjs组件,在其中一种方法中,我想发出一个ajax请求:Jquery 如何从我的reactjs组件发出跨域请求?,jquery,reactjs,axios,Jquery,Reactjs,Axios,我有一个reactjs组件,在其中一种方法中,我想发出一个ajax请求: $.ajax({ type: 'GET', crossDomain: true, url:'http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1', success: (res) => {
$.ajax({
type: 'GET',
crossDomain: true,
url:'http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1',
success: (res) => {},
error: (fail) => {}
})
加载组件时,请求加载失败,出现错误:
请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“”
是否有可能解决此问题,或者我应该采用不同的方法?要提出跨域请求,您应该使用jsonp或反向代理
http
tohttps
,但看起来该站点不支持SSL
到该网站为止,它应该允许跨域并为api内容启用SSL无法在客户端修复…端服务器需要启用CORSChange api端点至https://api.openweathermap.org/...
。默认情况下,它应该启用CORS。请求失败……拒绝从…执行脚本。。。因为它的MIME类型('application/json')不可执行,并且启用了严格的MIME类型检查。
$.ajax({
url:"http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1",
type:"GET",
jsonpCallback: "getStatus",
dataType: "jsonp",
});
function getStatus(response)
{
console.log(response);
}