execute javascript script inside a div loaded with ajax

1

I have an index.php which contains a div called content

in which I upload another file listarusuarios.php with the following script

    function ajaxFunction() {
var xmlHttp;

try 
{  
xmlHttp=new XMLHttpRequest();
return xmlHttp;
} catch (e) 
{

try 
{
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  return xmlHttp;
} catch (e) 
{

  try 
  {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlHttp;
  } catch (e) 
    {
    alert("Tu navegador no soporta AJAX!");
    return false;
    }}}
}




function Enviar(_pagina,capa)
{
var ajax;
ajax = ajaxFunction();
ajax.open("POST", _pagina, true);
ajax.setRequestHeader("Content-Type", "application/x-www-form- 
urlencoded");

ajax.onreadystatechange = function() {
    if (ajax.readyState==1){
        document.getElementById(capa).innerHTML = " Aguarde por 
   favor...";
             }
    if (ajax.readyState == 4) {

            document.getElementById(capa).innerHTML=ajax.responseText;

         }}

ajax.send(null);

 }

and I send the content of listarusers.php through a link

<a href="Javascript:Enviar('listarusers.php' , 
'contenido')">Enviar</a>

the file "listarusers.php" contains a script for calendar in jquery

    dhtmlXCalendarObject.prototype.langData["es"] = 
{
    dateformat: "%Y.%m.%d",
    monthesFNames: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", 
  "Junio", "Julio","Agosto", "Septiembre", "Octubre", "Noviembre", 
  "Diciembre"],
    monthesSNames: ["Ene", "Feb", "Mar", "Abr", "May", "Jun","Jul", 
 "Ago", "Sep", "Oct", "Nov", "Diz"],
    daysFNames: ["Domingo", "Lunes", "Martes", "Miercoles","Jueves", 
 "Viernes", "Sabado"],
    daysSNames: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"],
    weekstart: 1,
    weekname: "w"
};

var myCalendar;
function doOnLoad() 
{
    myCalendar = new dhtmlXCalendarObject(["cal_1", "cal_2", 
 "cal_3","cal_4", "cal_5", "cal_6","cal_7","cal_8","cal_9",]);
    myCalendar.setDate(new Date(2000,0,1,16,0));
    myCalendar.loadUserLanguage("es");
}

Html part of listarusers.php where I call the calendar about the input

The fact is that if I load listarusers.php in the browser, it works correctly, but if I send it to the div "content" through ajax, the calendar does not work. I have tried to declare the calendar script and the doOnLoad (); of the body in the index.php since it is loading on that layer and as well as dragging the css I assumed that it would also drag the JS but it seems that it does not.

    
asked by Borja Otero Ferreira 17.08.2018 в 20:06
source

0 answers