AHAH (Asynchronous HTTP and HTML) is a light version of AJAX (the buzzword these days) and it has some advantages: It's simpler to use and fits quite well with simple web pages.
In this tutorial we shall build a simple app using AHAH:
We'll have a dynamic page listing some items. When we pass the mouse over each item, the description will be requested from the server (without reloading the page) and it will be displayed as a tool tip next to it.
For this job we shall use 3 files:
- list_item.php: It will list the items
- item_details.php: It will be called using AHAH and will retrieve the requested description
Click here to download the sample files (3kb)
OK. Time to start. In the first chapter we'll create the 'item_details.php' file. The concept for this file is creating a detail page (but without any html) that will retrieve the data filtered by an URL parameter (id_item). The steps are:
- Create a php file, delete al the code and save it as 'item_details.php'
- Open the Data Bindings panel to create a new recordset
- This recordset will return the description for the items, but the data will be filtered by an url param called 'id_tem':
- Go to code view, and drag and drop the description field from the bindings panel just before the mysql_free_result() part. Wrap it with an echo function. The whole file will have around 14 lines of code as seen blow:
- Save the file and it's done.
As you can see, it's a very simple file (14 lines of code). Time to work with the main file: list_items.php
Next chapter: creating the main layout