I am developing a web application that needs to load modules dynamically, each module has html, css, javascript code fragments, which I upload via ajax with json:
To add the html and the css, the innerHTML method works perfectly for me, which is not the case with Javascript.
here is the code of the petition and answer:
//esta seria la peticion
function requestApplication(e){
var solicitud = new XMLHttpRequest();
solicitud.addEventListener('load', requestAplicacionResponse, false);
var aplicacion = e.target;
var modulo = aplicacion.parentNode.parentNode;
var sucursal = modulo.parentNode.parentNode;
var dataset = sucursal.dataset;
var url = 'http://' + dataset.host + ':' + dataset.port + '/sistema/aplicacion';
var paquete = {
'sesion':sucursal.dataset.sesion,
'usuario':sucursal.dataset.usuario,
'perfil': sucursal.dataset.perfil,
'modulo': modulo.dataset.modulo,
'aplicacion': aplicacion.dataset.aplicacion
};
solicitud.open('POST', url);
solicitud.send(JSON.stringify(paquete));
}
//este metodo recibe la respuesta del servidor
function requestAplicacionResponse(e){
var main = document.querySelector('main');//contenedor donde quiero agregar lo solicitado
//obj es un diccionario clave valor "objeto json" que contiene el codigo que deseo agregar
var obj = JSON.parse(e.target.responseText);
main.innerHTML = main.innerHTML + obj.html + obj.css + obj.js;
}
is displayed correctly but has no functionality, apparently it seems that the javascript functions were not added to the javascript interpreter associated with the DOM of the page.