Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Using Ajax with PHP and Sajax

How the Simple Ajax Toolkit can integrate your server-side PHP with JavaScript

Tyler Anderson (tyleranderson5@yahoo.com), Freelance Writer, Stexar Corp.
Tyler Anderson graduated with a degree in computer science from Brigham Young University in 2004 and is currently in his last semester as a master's student in computer engineering. In the past, he worked as a database programmer for DPMG.com, and he is currently an engineer for Stexar Corp., based in Beaverton, Ore.

Summary:  For years, the goal of creating a truly responsive Web application was hampered by one simple fact of Web development: To change the information on part of a page, a user must reload the entire page. Not anymore. Thanks to asynchronous JavaScript and XML (Ajax), we can now request new content from the server and change just part of a page. This tutorial explains how to use Ajax with PHP and introduces the Simple Ajax Toolkit (Sajax), a tool written in PHP that lets you integrate server-side PHP with JavaScript that makes this work.

Date:  05 Jul 2006 (Published 18 Oct 2005)
Level:  Intermediate PDF:  A4 and Letter (328 KB | 24 pages)Get Adobe® Reader®

Activity:  34264 views
Comments:  

Before you start

This tutorial is for those interested in developing rich Web applications that dynamically update content using asynchronous JavaScript and XML (Ajax) with PHP, without having to refresh entire Web pages with each user click. This tutorial assumes basic PHP concepts, including the use of if and switch statements, and functions.

About this tutorial

You will learn about Ajax, as well as issues surrounding its usage. You will also build an Ajax application in PHP that will display panels of a section of a previously written tutorial. Clicking on a panel link will reload only the content section and replace it with the content of the selected panel, saving bandwidth and time loading the page. Then you will integrate the Simple Ajax Toolkit (Sajax) into your Ajax application, which will synchronize the use of Ajax, simplifying development.


Prerequisites

The following tools are needed to follow along:

Web server
Pick any Web server and operating system. Feel free to use Apache 2.X or the IBM HTTP Server.
PHP
You can follow along without PHP, but if you are interested in interacting with the sample application download PHP V5.
Sajax
You will need Sajax. This is a single-file library of PHP functions used in this tutorial.
Web browser
You will need a Web browser that supports JavaScript. These include Mozilla, Firefox, Opera, and Microsoft Internet Explorer.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, XML
ArticleID=133619
TutorialTitle=Using Ajax with PHP and Sajax
publish-date=07052006
author1-email=tyleranderson5@yahoo.com
author1-email-cc=troy@backstopmedia.com