I have this script that I made I am unsure how I can do this. I basically want to append an ajax request response on the page without refreshing in other words x.php has an iframe youtube video and I want to be able to watch one of the iframe videos
while i'm pressing the button to append more ajax request from x.php. This script appends but interrupts the other already appended ajax request divs.
My code
test.php
<script>
document.addEventListener('DOMContentLoaded', function(){
document.querySelector('#executeAjax').addEventListener('click', sendAjax);
function sendAjax(){
var xhr= new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
document.querySelector('#ajax').innerHTML += xhr.responseText;
}
}
xhr.open('POST','x.php');
xhr.send();
}
});
</script>
<button id='executeAjax'>Execute</button>
<div id='ajax'></div>
x.php
<iframe width="420" height="345" src="https://www.youtube.com/embed/tgbNymZ7vqY"></iframe>