Have called another page through XMLHttpRequest. But the called page can't return JavaScript content.
In below code it's not returning addition of 5+7.
Have gone through various google stuff but nothing seems to be working.
it would be helpful if anyone could crack that....
request_xml.php
<!DOCTYPE html>
<html>
<body>
<p id="demo">Here</p>
<script>
window.onload = function() {
loadDoc();
};
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "call_page.php", true);
xhttp.send();
}
</script>
</body>
</html>
call_page.php
<!DOCTYPE html>
<html>
<body>
<p>why is js not working?</p>
<script>
document.write(5+7);
</script>
</body>
</html>
Edit:
JavaScript is working when page directly loaded
Also, JS working inside onclick in call_page.php