13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

860 Chapter 34 Building <strong>Web</strong> 2.0 Applications with Ajax<br />

Server-Side Programming<br />

Server-side programming includes all scripts that reside on a web server <strong>and</strong> are interpreted<br />

or compiled before sending a response to the client. Server-side programming<br />

typically includes server-side connections to databases; requests <strong>and</strong> responses to <strong>and</strong><br />

from a database are thus part of the scripts themselves.<br />

These scripts could be written in any server-side language, such as Perl, JSP, ASP, or<br />

<strong>PHP</strong>—the latter being the language used throughout the examples in this chapter for<br />

obvious reasons. Because the response of a server-side script is typically to display data<br />

marked up in some variant of st<strong>and</strong>ard HTML, the end-user environment is of little<br />

concern.<br />

XML <strong>and</strong> XSLT<br />

You were introduced to XML in Chapter 33,“Connecting to <strong>Web</strong> Services with XML<br />

<strong>and</strong> SOAP,” which included basic information on the format, structure, <strong>and</strong> use of XML.<br />

In the context of Ajax applications, XML—the “X” in Ajax—is used to exchange data;<br />

XSLT is used to manipulate the data.The data itself is either sent through or retrieved<br />

from the Ajax application you create.<br />

For more information on XML, see http://www.w3.org/XML/, <strong>and</strong> for more information<br />

on XSL, see http://www.w3.org/TR/xslt20/.<br />

Fundamental Ajax<br />

Now that you’ve learned the possible constituent parts of an Ajax application, this section<br />

will put those pieces together to produce a working example of this technology in<br />

action. Keep at the forefront of your mind one of the main reasons for using Ajax in the<br />

first place: to produce interactive sites that respond to user actions but without the interruption<br />

that comes from refreshing an entire page.<br />

To achieve the this goal, an Ajax application includes an extra layer of processing that<br />

occurs between the requested web page <strong>and</strong> the web server responsible for producing<br />

that page.This layer is commonly referred to as an Ajax Framework (also an Ajax<br />

Engine).The framework exists to h<strong>and</strong>le requests between the user <strong>and</strong> the web server,<br />

<strong>and</strong> it communicates the requests <strong>and</strong> responses without additional actions such as<br />

redrawing a page <strong>and</strong> without interruption to whatever actions the user is currently performing,<br />

such as scrolling, clicking, or reading a block of text.<br />

In the next few sections, you’ll learn how the different parts of an Ajax application<br />

function together to produce a streamlined user experience.<br />

The XMLHTTPRequest Object<br />

Earlier in this chapter, you learned about HTTP requests <strong>and</strong> responses <strong>and</strong> also how<br />

client-side programming can be used within an Ajax application.The specific JavaScript<br />

object called XMLHTTPRequest is crucial when connecting with the web server <strong>and</strong> making<br />

a request without entirely reloading the original page.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!