Hello guys I want to know how I can allow JS to be enable effectively on each ajax requested page.
These are my files I need to allow JS to work thru.
page_1.php
<script>
document.addEventListener('DOMContentLoaded', function(){
var execute_sendAjax1 = document.getElementById('executeAjax1');
execute_sendAjax1.addEventListener('click', sendAjax1);
function sendAjax1(){
var xhr1= new XMLHttpRequest();
xhr1.onreadystatechange = function(){
if(xhr1.readyState === 4){
document.getElementById('ajax1').innerHTML= xhr1.responseText;
}
}
xhr1.open('POST','page_2.php');
xhr1.send();
}
});
</script>
<button id='executeAjax1'>Execute 1</button>
<h1>Page 1</h1>
<div id='ajax1'></div>
page_2.php
<script>
var execute_sendAjax2 = document.getElementById('executeAjax2');
execute_sendAjax2.addEventListener('click', sendAjax2);
function sendAjax2(){
var xhr2= new XMLHttpRequest();
xhr2.onreadystatechange = function(){
if(xhr2.readyState === 4){
document.getElementById('ajax2').innerHTML= xhr2.responseText;
}
}
xhr2.open('POST','page_3.php');
xhr2.send();
}
</script>
<button id='executeAjax2'>Execute 2</button>
<h1>Page 2</h1>
<div id='ajax2'></div>
page_3.php
<script>
var execute_sendAjax3 = document.getElementById('executeAjax3');
execute_sendAjax3.addEventListener('click', sendAjax3);
function sendAjax3(){
var xhr3= new XMLHttpRequest();
xhr3.onreadystatechange = function(){
if(xhr3.readyState === 4){
document.getElementById('ajax3').innerHTML= xhr3.responseText;
}
}
xhr3.open('POST','page_4.php');
xhr3.send();
}
</script>
<button id='executeAjax3'>Execute 3</button>
<h1>Page 3</h1>
<div id='ajax3'></div>
page_4.php
<h1>Page 4</h1>
What I have tried:
I have looked online for a long time on this topic not a lot of easy to understand sources.