0

I have a problem with my Function. Once i print a page from XMLHttpRequest from the php side server with a unique link it doesnt recognize the scripts that are in the page at the php side server. it says undefined Functions in Jquery.

Thank you.

if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var iDiv = document.createElement('div');
        iDiv.id = '22';
        iDiv.className = '2323';
        iDiv.innerHTML = xmlhttp.responseText;
        iDiv.innerHTML += '<script type=\"text/javascript\" src=\"https://d3v2hnl706774i.cloudfront.net/html/iframeResizer.min.js\"></script>';
        iDiv.innerHTML += '<script type=\"text/javascript\">iFrameResize({log: false,enablePublicMethods: true,enableInPageLinks: true,minHeight: 300});</script>';
        document.getElementsByTagName('body')[0].appendChild(iDiv);
        thisScriptElement.parentNode.insertBefore(iDiv, thisScriptElement);
        thisScriptElement.parentNode.removeChild(thisScriptElement);
    }
}
xmlhttp.open("GET", theUrl, true);
xmlhttp.send(null);
}
Pointy
  • 405,095
  • 59
  • 585
  • 614
idan traders
  • 79
  • 1
  • 7
  • ok i see but how i can insert the RVAL() function to my code i don׳t understand how. you can help me with this? – idan traders Sep 03 '15 at 14:29
  • What is RVAL() and where does it go now? – mplungjan Sep 03 '15 at 14:33
  • i have the anser here: http://stackoverflow.com/questions/4619668/executing-script-inside-div-retrieved-by-ajax the answer is function in javascript call rval() but i don't undrstand how i need to insert to my code – idan traders Sep 03 '15 at 14:42

1 Answers1

0

That is because innerHTML does not run the scripts.

You need to add them to the head of the page

Try this

 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    var iDiv = document.createElement('div');
    iDiv.id = '22';
    iDiv.className = '2323';
    iDiv.innerHTML = xmlhttp.responseText;
    document.getElementsByTagName('body')[0].appendChild(iDiv);
    var s1 = document.createElement("script"); 
    s1.src="https://d3v2hnl706774i.cloudfront.net/html/iframeResizer.min.js";
    document.getElementsByTagName('head')[0].appendChild(s1);
    setTimeout(function() { iFrameResize({log: false,enablePublicMethods: true,enableInPageLinks: true,minHeight: 300})},100);
}

Or since you tagged jQuery, look into getScript

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Sorry i will re-explain my problem, The function prints the data exactly as intended, But Inside the Data there are more jQuery functions that imports more data with the function OnClick. Once i click on the list inside the data i get undefind function – idan traders Sep 03 '15 at 14:04
  • thanks i figured it do that thanks for all the help – idan traders Jan 07 '16 at 09:36