Click here to Skip to main content
13,769,019 members
Rate this:
 
Please Sign up or sign in to vote.
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
<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 3-Jan-18 10:59am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181117.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100