The code is a function in AJAX that receives from a PHP page 2 variables: id
and nombrediv
. nombrediv
is the id of the div where I want to show the result of the ajax function, but it does not work.
Can this be done?:
document.getElementById(VARIABLE)
What is the way to write it?
var editarMedidas = function(id, nombrediv) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "editar-medidas.php?id=" + id + "&nd=" + nombrediv);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if(xhr.status == 200) {
// AQUI ES EL PROBLEMA, SE PUEDE PONER UNA VARIABLE PARA QUE BUSQUE LA DIV CON ESE NOMBRE?
var caja=document.getElementById(nombrediv);
caja.innerHTML = xhr.responseText;
}
}
}
xhr.send(null);
}