0
Good afternoon, I have been programming for some years and I am well accommodated with the use of Jquery
, and it is very common to make calls AJAX
where a file is received as a response JSON
, however I almost never did it in a "pure" way, in other words, without Jquery, and wanted to understand in a slightly more explained way how to perform this request.
The question is, how do I collect the data
that the file will return?
Currently my code is written this way:
//On load eveneto
window.onload = async function(){
//Chamando o Ajax
let value = await requestJson();
console.log(value);
}
async function requestJson(){
//Retornando uma promessa
return new Promise((resolve, reject) => {
//[+] AJAX_________
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
resolve(this.responseText);
}
xhttp.open("GET", "file.json", true);
xhttp.send();
//[-] AJAX_________
});
}
NOTE : Stack Overflow Brazil ta with negative bot, I did not ask the question two minutes, and I was negative in my question. =/
– WEB Last Wolf