I am loading html content into a div using XMLHttpRequest() It works fine with just html, but if I add any javascript functions to the html content, I get a function undefined error when I try to use them.
When "main_table_html.php" finishes loading, the javascript function inside called "we_are_loaded()", should be executable, but it returns an error of undefined.
I inherited this code and I'm not sure what to do here:
Here is the code:
// Main Load XML Doc Function
function loadXMLDoc(url,cfunc) {
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=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
} // end of load xml doc
function btnClick(item) {
loadXMLDoc(item,function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("MainContent").innerHTML=xmlhttp.responseText;
if(item == 'main_table_html.php'){
we_are_loaded();
}
}
});
return "complete";
}