0
I am trying to upload data from a json file to an html table.
I’m trying to rescue the json this way:
function getJson(){
$.getJSON('dados/livros.json', function(data){
console.log(data);
});
}
Example of json I’m trying to rescue:
{
"livros": [
{
"id":1,
"imagem":"images/JavaScriptEJquery.jpg",
"nome":"Javascript e Jquery - Desenvolvimento de Interfaces Web Interativas",
"autor":"JON DUCKETT",
"genero":"Didatico",
"anoEdicao":"2016",
"editora":"AltaBooks",
"estado":"Disponivel"
},
{
"id":2,
"imagem":"images/ScrumAArteDeFazerODobroNaMetadeDoTempo.jpg",
"nome":"Scrum - A Arte de Fazer o Trabalho na Metade do Tempo",
"autor":"JEFF SUTHERLAND",
"genero":"Didatico",
"anoEdicao":"2016",
"editora":"LEYA",
"estado":"Indisponivel"
}
]
}
Location of the json file:
Error:
jquery-3.3.1.js:9600 Access to Xmlhttprequest at 'file://D:/Catalogo%20de%20Livros/dados/livros.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https.
I’ve been doing some research but I haven’t been able to solve this problem, I’ve never come across this error before. What is the cause of this error ? how to resolve ?
Levi, I think your problem is the same as this one, check it out: https://stackoverflow.com/questions/27742070/angularjs-error-cross-origin-requests-are-only-supported-for-protocol-schemes
– Mike