/me kicks self
Granted I've only covered the basic idea but the rest is history once you have that down.
Simplest bit of AJAX possible.
Client side:
Code: Select all
<script type="text/javascript">
<!--
//For cross browser compatibility you'd do some checking but that's nothing to do with AJAX itself
var http = new XMLHttpRequest();
function showText()
{
//Send the GET request
http.open("GET", 'server_script.php', true);
//When response is received, pass to this callback function
http.onreadystatechange = handleResponse;
//Send the request
http.send(false);
}
function handleResponse()
{
if (http.readyState == 4) //If successful
document.getElementById('foo').innerHTML = http.responseText;
}
// -->
</script>
<a href="javascript:showText();">Click here to get AJAX data</a>
<div id="foo">Text will show here</div>Code: Select all
<?php
echo "Yes... It works!";
?>//Pardon the excitement