No me funciona
Pero me dao cuenta que la funcion anterior , me avisa que se ha generado un nuemo numero pero no lo muestra por consola, la funcion es esta
function inicioJSON() {
var xmlHttp = new XMLHttpRequest();
var urlDestino = "aciertaNumeroJSON.php?inicio=hola";
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
var respuesta = xmlHttp.responseText;
console.log(respuesta, typeof respuesta);
var obj = JSON.parse(respuesta);
console.log(obj, typeof obj);
console.log("El número aleatorio que devuelve la consulta es: ", obj.inicio);
document.getElementById('mensaje').innerHTML = "Se ha generado un nuevo numero";
}
};
xmlHttp.open("GET", urlDestino, true);
xmlHttp.send();
}
y la funcion checkAJaxJson
function checkAjaxJSON() {
var xmlHttp = new XMLHttpRequest();
var numPropuesto = document.getElementById('numero').value;
var urlDestino = 'aciertaNumeroJSON.php?numero=' + numPropuesto;
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
var respuesta = xmlHttp.responseText;
var obj = JSON.parse(respuesta);
document.getElementById('encontrado').innerHTML = obj.respuesta.encontrado;
document.getElementById('mensaje').innerHTML = obj.respuesta.mensaje;
}
};
xmlHttp.open("GET", urlDestino, true);
xmlHttp.send();
}