An Introduction to AJAX

0
Your rating: None

Of all the buzzwords to enter the computer lexicon in the past couple of years, Ajax may be the “buzziest.” Ajax, which stands for Asynchronous JavaScript and XML (or not, depending upon whom you ask), changes the client/server relationship so that server interactions can take place without any apparent action on the part of the client. In truth, Ajax is just a label given to functionality that’s been present for years, but sometimes a good label helps, and when a powerhouse like Google uses Ajax (for Gmail, Google Suggest, and more), people pay attention.

As you know, PHP is primarily a Web-based technology (although it can be used from the command line—see. This means that PHP does its thing whenever a server request is made. A user goes to a Web page or submits a form; the request is made of the server; PHP handles that request and returns the result. Each execution of some PHP code requires an active request and a redrawing of the Web browser. For the end user, this means they see their browser leave the current page, access the new one, download the new page’s content, and display the content, repeating as necessary.

The secret to Ajax is that it can make the server request happen behind the scenes while still changing what the user sees as if they actively made the server request. JavaScript is really the key technology here. With an Ajax transaction, JavaScript, which does its thing within a Web browser, makes
the request of the server and then handles that request. The Web page can then be updated without ever seeming to leave the current page. In action, this
might mean:

1. The end user goes to a Web page.
2. The user types something in a box, clicks a button, or drags something with their cursor.
3. Whatever the user does in Step 2 triggers JavaScript to request something from the server.
4. The server handles that request (using PHP in this chapter), returning some data.
5. JavaScript receives that data and uses it to update the Web page, without reloading it.

Looking at all the technologies involved, you start with (X)HTML, which is the
foundation of all Web pages. Then there’s JavaScript, which runs in the Web browser, asks for and receives data from the server, and manipulates the HTML by referring to the Document Object Model (DOM, an object-based representation of the elements of a Web page). And finally, on the server, you have our friend PHP. The last technology commonly involved is XML (Extensible Markup Language), which can be used in the data transfer. I say “can be,” because you don’t have to use XML.

■ Jesse James Garrett coined the term Ajax in February 2005. He has since claimed that Ajax is not an acronym. It just, you know, seems like an acronym.

What Is Asynchronous?

One of the key components of Ajax is itsasynchronous behavior. This term, which
literally means not synchronous, refers to a type of communication where one side (say, the client) does not have to wait for the other side (the server) before doing something else. In an asynchronous transaction, the user can do something that makes the JavaScript request data from the server. While the JavaScript is awaiting that data, which it’ll then display in the Web browser, the user is free to do other things, including other things that involve JavaScript. So the asynchronicity makes the experience more seamless. On the other hand, you can perform synchronous transactions, if you are in a situation where the user should wait until the data is in.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India