Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I been researching for a long time and i'm so confused I read that you have to use the eval() function so plain ajax can recognize and execute the JavaScript on the other page I read thru a lot of sites but there is rarely no info on this or no examples that makes sense to me so can any one add the right code to my code to get this to work. I'm a visual learner.

index.php
HTML
<script>
var xhr= new XMLHttpRequest();
xhr.onreadystatechange= function(){
    if(xhr.readyState === 4){
        document.getElementById('ajax').innerHTML= xhr.responseText;
    }
};
xhr.open('POST','x.php');

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.php
<script>
alert('js is executed');
</script>

<h1>Radom text</h1>


What I have tried:

I have gone to other chat sites but no good answers usually confusing links were provided. And this is rarely mentioned on google so yeah.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900