ajax - server-side php script
We completed the "order.html" file in the Previous Lesson, but we had our Ajax linking to a PHP script that did not yet exist. This lesson will walk you through the process of creating a simple PHP script that displays the current server time.
ajax - servertime.php file
The XMLHttpRequest property, responseText, will store the data that this PHP script displays to the browser, so all we want this script to do is Echo the current time. If you would like a refresher on how to use PHP's date function, you can check out our PHP Date Tutorial. The php code below should be saved in the same directory as "order.html".
serverTime.php PHP Code:
<?php
echo date("H:i:s");
?>
ajax - run your ajax!
Below is a working version of the simple, yet super cool, Ajax application you have just created! To test it out just type some text into the "Name:" text box, then click inside the "Time:" text box.
Display of order.html:
Sweet! The time text box pulled down the server's time from "serverTime.php" without having to reload the entire page! Congratulations you've just written your first fully-functional Ajax application!
ajax - continued learning
That's all for now folks! If you're feeling adventerous about taking your Ajax skills to the next level, then I highly recommend you check out IBM's Master Ajax Series.
EmoticonEmoticon