This example was supposed to be included in the previous post, How to use AJAX with JSON and without jQuery, but that post just kept growing, to the point where it got to long be manageable. So what you see here is just the phone-book example that I mentioned in that post.
Please remember that this is about learning how to use AJAX – not about creating a good phone-book. This is a very simple application; The database file contains 50 made-up persons, and there is no functionality for editing the database – you can only search what is already there. That’s the only functionality of the application: searching the database.
If you don’t feel like implementing the example yourself, you can still try it out on my web site through this link.
If you do want to implement the example yourself, it’s as easy as copying all three files below to the same directory on a web server.
The application components
The application components all reside on the web server, and the only one that you will access directly is
phonebook.html, which is the HTML document that you will open in your web browser.
Then there is the PHP script
phonebook_connector.php. You can open this directly in your web browser, but that would be pointless. This script is listening for AJAX requests on JSON format, and navigating to it through your browser will just get you a pages with two square brackets, “
“. If you know a little about the JSON format, you might recognize this as representing an empty JSON array, and that is what the script gives you when you don’t ask for anything in particular.
And finally there is the phone-book database file,
I have placed the description of each of the three components on a separate page below.