Sto utilizzando l'API di recupero HTML5.Autorizza l'intestazione Access-Control-Allow-Origin utilizzando l'API di recupero HTML5
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)
});
Sono in grado di utilizzare il json normale ma non riesco a recuperare i dati di sopra api url. getta errore:
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.
Il server di terze parti deve impostarlo, non c'è nulla che tu possa fare sul clientide. – epascarello
@epascarello: Possiamo fare dal lato del cliente. Dietro la scena, XHR Request sta succedendo. Per favore controlla questo 'https: // davidwalsh.name/fetch' – iNikkz