The following is not my actual project, but an example that has the same problem as my project.
Here's the main HTML page snippet:
<div id="divExample">Before</div>
<script type="text/javascript">
loadExample();
</script>
Here's the javascript file snippet:
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('divExample').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","mypanel.html",true);
xmlhttp.setRequestHeader("If-Modified-Since", "Sun, 31 Dec 1899 23:59:59 GMT");
xmlhttp.send();
Here's the fetched mypanel.html:
After
<script type="text/javascript">
alert("Fetched script is working.");
</script>
When I load the main HTML page, the AJAX javascript runs fine. It fetches mypanel.html and puts its contents in divExample.innerHTML. The word "After" correctly shows instead of "Before".
However, the script with the alert never executes. I would not like to separate the alert script from mypanel.html. Any ideas how I can make it execute after AJAX loads it?
I've read here that this can be done.
I've read here that this cannot be done.
Any ideas how to make it happen?