I have an HTML with JS element that I need to load on runtime.
These are some example files to illustrate the functionality I'm looking for.
File 1: index.html
<div id="mydiv"> </div>
<script type="text/javascript">
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","script.php",false);
xmlhttp.send();
var text=xmlhttp.responseText;
var elem=document.getElementById("mydiv")
elem.innerHTML=text
func()
</script>
File 2: script.php
<script type="text/javascript">
function func(){
alert("func")
}
</script>
ERROR returned by browser:
Inline script thread
Uncaught exception: ReferenceError: Undefined variable: func Error thrown at line 20, column 0 in localhost/my_project/: func()