1
I am iterating with php and javascript and I have a problem. Javascript triggers the php file and receives the php array via json_encode. After that, I can read the array in Javascript, but I can’t use it for other treatments. Follow the codes:
var retorno;
var requisicao = new XMLHttpRequest();
requisicao.onload = reqListener;
requisicao.open("get", "../scr/farol_laudos_action.php", true);
requisicao.send();
function reqListener() {
var dados = JSON.parse(this.responseText);
retorno = dados;
};
alert(retorno[0]);
This way it is, it returns the blank page. What am I doing wrong? Thank you in advance!
In the query itself it is possible to define whether to use it asynchronously or synchronously.
httpRequest.open('GET', 'url', true);
This last parameter defines whether the function is asynchronous or synchronous.– Pedro Henrique
Eric Santana, thanks for the explanation! For the moment, I changed the parameter to false so that it works synchronously as mentioned, but I will study the asynchronous form. Thank you!
– Marco Cardoso Clares