¿alguien puede decirme que tiene mal este código para que me devuelva el fallo: Uncaught ReferenceError: responseText is not define
function loadDoc() {
var xhttp = new XMLHttpRequest();
var data;
xhttp.open("GET", "tiempoPasoEstacionesAvisos.php", true);
xhttp.send();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
data = JSON.parse( xhttp.responseText );
}
};
}
En el PHP los datos enviados los tengo de esta manera:
echo json_encode($_SESSION["tiemposParaAvisoEstación"],JSON_FORCE_OBJECT);
this
porxhttp
dentro de la función y 2. Mueve elsend
, poniéndolo al final. De modo que todo quede así:xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { data = JSON.parse( xhttp.responseText ); } }; xhttp.send();