我在使用React和Express的同构JavaScript应用程序中遇到了一个问题.
我正在try 使用axios发出HTTP请求.等我的组件安装好
componentDidMount() {
const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders';
axios.get(url).then( res => {
//use res to update current state
})
}
我从API中获得状态200 res,但我没有得到任何响应数据,也没有在控制台中得到错误
XMLHttpRequest cannot load http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
但是,如果我在我的服务器上发出请求.js
const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders';
axios.get(url).then(res => {
//console.log(res);
});
它工作正常,在服务器启动时我会收到响应数据.这是实际API的问题还是我做错了什么?如果这是CORS问题,我猜是服务器中的请求.js也不行吗?谢谢