Ok I have these two working code files so I decided to add JavaScript on a page call x.html so I expected the JavaScript to run after I push the AJAX button that is located in a page call index.html so everything executes but no JavaScript is executed on x.html just the HTML is executed.
So I read you have to use eval() to make AJAX notice and execute the JavaScript on the other page that it is calling AKA x.html.
Here's the code
index.html
<script>
var xhr= new XMLHttpRequest();
xhr.onreadystatechange= function(){
if(xhr.readyState === 4){
document.getElementById('ajax').innerHTML= xhr.responseText;
}
};
xhr.open('POST','x.html');
function startAjax(){
xhr.send();
document.getElementById('hide_button').style.display= 'none';
}
</script>
<body>
<button id='hide_button' onclick='startAjax()'>Start</button>
<div id='ajax'></div>
</body>
x.html
<!DOCTYPE html>
<html>
<head>
<script>
alert('hello');
</script>
</head>
<body>
<h1>Radom text</h1>
</body>
</html>