Bookmark and Share

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.

Advertise on

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:

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.

Bookmark and Share

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials