Can’t access json file because “Access to XMLHttpRequest at ‘file://XX.json’ from origin ‘null’ has been blocked by CORS policy”

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

Currently trying to make a table in html that uses simple javascript to load data from a json file into it and creates the table with that data. However, the console is giving me an error that says: “Access to XMLHttpRequest at ‘file:///C:/Users/Nuno/Documents/PTW/F4/Autenticacoes-Evolucao-por-Certificado.json’ from origin ‘null’ has been blocked by CORS policy” and I’m not sure why this is happening. Leaving both html and javascript below.

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<script src=”http://code.jquery.com/jquery-1.11.0.min.js”></script>
<script src=”Autenticacoes-Evolucao-por-Certificado.json”></script>
<link href=”leitura.css” rel=”stylesheet”>
</head>
<body>
<table id=”info”>
<th class=”div” id=”Ano”>Ano</th>
<th class=”div” id=”Mes”>Mês</th>
<th class=”div” id=”Chave-Movel-Digital”>CMD</th>
<th class=”div” id=”Cartao-Cidadao”>CC</th>
<th class=”div” id=”Advogado”>Advogado</th>
<th class=”div” id=”Solicitador”>Solicitador</th>
<th class=”div” id=”Notario”>Notario</th>
</table>
<script src=”leitura.js”></script>
</body>
</html>

$(document).ready(function () {

$.getJSON(“Autenticacoes-Evolucao-por-Certificado.json”,
function (data) {
var infoTb = ”;

$.each(data, function (key, value) {

infoTb += ‘<tr>’;
infoTb += ‘<td>’ +
value.Ano + ‘</td>’;

infoTb += ‘<td>’ +
value.Mes + ‘</td>’;

infoTb += ‘<td>’ +
value.Chave-Movel-Digital + ‘</td>’;

infoTb += ‘<td>’ +
value.Cartao-Cidadao + ‘</td>’;

infoTb += ‘<td>’ +
value.Advogado + ‘</td>’;

infoTb += ‘<td>’ +
value.Solicitador + ‘</td>’;

infoTb += ‘<td>’ +
value.Notario + ‘</td>’;

infoTb += ‘</tr>’;
});

$(‘#info’).append(infoTb);
console.log(infoTb);
});
});

‫أضف إجابة

تصفح
تصفح

مجهول يجيب