I've already searched the forum here, I've got examples ready on other sites, but none of them worked for me.
As I said in the title, I am not able to make a link from a .json
file into the .js
file.
This is my file script.js
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'dados.json', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
My file dados.json
:
{
"rgV":"50.000.000-0",
"veiculoV":"Carro",
"dataV":"20/08/2018",
"blocoV":"A","aptoV":"12",
"placaV":"DWK - 3818",
"horaV":"13:18h",
"nomeV":"Nome Sobrenome",
"empresaV":"Alguma Empresa"
}
And in my HTML, I call the script.js page like this:
<script src="script.js"></script>
Anyway, I open the console and the browser does not return any errors ... Sorry if I was not very clear. Summarizing everything, I'm not able to include the JSON
file inside my javascript