我正在使用HTML5 fetch API。
var request = new Request('https://davidwalsh.name/demo/arsenal.json');
fetch(request).then(function(response) {
// Convert to JSON
return response.json();
}).then(function(j) {
// Yay,`j` is a JavaScript object
console.log(JSON.stringify(j));
}).catch(function(error) {
console.log('Request Failed',error)
});
我能够使用普通的json但无法获取上述api url的数据。
它抛出错误:
Fetch API cannot load https://davidwalsh.name/demo/arsenal.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. If an opaque response serves your needs,set the request's mode to 'no-cors' to fetch the resource with CORS disabled.