Hey all, Im having problems using ajax. This is what im trying to achieve - put simply, The html contents of a div tag to be replaced with the html of a file called page1.html - after clicking a text link. Could anyone give me example of how to do this? i have tried things online and just got confused. would appreciate an example that ill use as a template. Thanks Paul
try this out: <script language="javascript"> function get_page(target,url){ var http = new XMLHttpRequest(); http.open("GET", url, true); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { document.getElementById(target).innerHTML = http.responseText; } } } </script> usage: <div id="content"> </div> <a href="" onclick="get_page('content','page1.html');">Page</a>
The PHP page (the "url" in http.open("GET", url, true) has to echo the HTML you want inserted into the div.