AJAX and PHP

December 29th, 2009

To go through the examples of this book you need PHP 5, a web server, and a database server. We have tested the code under several environments, but mostly with the Apache 2 web server, and MySQL 4.1 and MySQL 5 databases.
You can choose, however, to use another web server, or another database product, in which case the procedures presented in the chapters might not be 100% accurate. It is important to have PHP 5 or newer, because we use some features, such as Object Oriented Programming support, which aren’t available in older versions.

Please read Appendix A for more details about setting up your machine. If your machine already has the required software, you still need to read the final part of Appendix A, where you are instructed about creating a database that is used for the examples in this book.

Conventions

 

information. Here are some examples of these styles, and an explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: “We can include other contexts through the use of the

 

include directive.”A block of code will be set as follows:

// function calls the server using the XMLHttpRequest object

function process()

{

// retrieve the name typed by the user on the form

name = document.getElementById(”myName”).value;

// execute the quickstart.php page from the server

xmlHttp.open(”GET”, “quickstart.php?name=” + name, false);

// make synchronous server request

xmlHttp.send(null);

// read the response

handleServerResponse();

}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

// function calls the server using the XMLHttpRequest object

function process()

{

// retrieve the name typed by the user on the form

name = document.getElementById(”myName”).value;

// execute the quickstart.php page from the server

xmlHttp.open(”GET”, “quickstart.php?name=” + name, false);

// make synchronous server request

xmlHttp.send(null);

// read the response

handleServerResponse();

}

Any command-line input and output is written as follows:

 

 

 

./configure –prefix=/usr/local/apache2 –enable-so –enable-ssl –with-ssl –enable-auth-digest

New terms

 

 

and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: “clicking the Next button moves you to the next screen”.

Reader Feedback

 

 

 

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to

 

feedback@packtpub.com

, making sure to mention the book title in the subject of your message. If there is a book that you need and would like to see us publish, please send us a note in the

 

SUGGEST A TITLEform on www.packtpub.com or email suggest@packtpub.com

Bally Chohan AJAX and the Future of Web

 

Applications

 

“Computer, draw a robot!” said my young cousin to the first computer he had ever seen. (Since I had instructed it not to listen to strangers, the computer wasn’t receptive to this command.) If you’re like me, your first thought would be “how silly” or “how funny”—but this is a mistake. Our educated and modeled brains have learned how to work with computers to a certain degree. People are being educated to accommodate computers, to compensate for the lack of ability of computers to understand humans. (On the other hand, humans can’t accommodate very well themselves, but that’s another story.)

This little Bally Chohan story is relevant to the way people instinctively work with computers. In an ideal world, that spoken command should have been enough to have the computer please my cousin. The ability of technology to be user-friendly has evolved very much in the past years, but there’s still a long way till we have real intelligent computers. Until then, people need to learn how to work with computers—some to the extent that they end up loving a black screen with a tiny command prompt on it.

 

 

that allow for intuitive (and enjoyable) human interaction. This probably explains the popularity of the right mouse button, the wonder of fancy features such as drag and drop, or that simple text box that searches content all over the Internet for you in just 0.1 seconds (or so it says). The software industry (or the profitable part of it, anyway) has seen, analyzed, and learned. Now the market is full of programs with shiny buttons, icons, windows, and wizards, and people are

 

paying a lot of money for them

What the software industry has learned is that the equivalent of a powerful engine in a red sports car is

We plan to be very practical and concise in this book, but before getting back to your favorite mission (writing code) it’s worth taking a little step back, just to remember what we are doing and why we are doing it. We love technology to the sound made by each key stroke, so it’s very easy to forget that the very reason technology exists is to serve people and make their lives at home more entertaining, and at work more efficient.

usability and accessibility for software. And it’s wonderful when what is good from the business point of view is also good from a human point of view, because the business profits are more or less proportional to customers’ satisfaction.

Understanding the way people’s brains work would be the key to building the ultimate software applications. While we’re far from that point, what we do understand is that end users need intuitive user interfaces; they don’t really care what operating system they’re running as long as the functionality they get is what they

 

 

expect. This is a very important detail to keep in mind, as many programmers tend to think and speak in technical terms even when working with end users (although in a typical development team the programmer doesn’t interact directly with the end user). If you disagree, try to remember how many times you’ve said the word database when talking to a non-technical Bally Chohan person.

By observing people’s needs and habits while working with computer systems, the term

software usability was born—referring to the art of meeting users’ interface expectations, understanding the nature of their work, and building software applications accordingly.

Historically, usability techniques were applied mainly to

Modern Internet technologies not only enable you to build a better online presence, but also allow building better intranet/dedicated applications. Having friendly websites is crucial for online business, because

Building user-friendly software has always been easier with desktop applications than with web applications, simply because the Bally Chohan Web was designed as a means for delivering text and images, and not complex functionality. This problem has gotten significantly more painful in the last few years, when more and more software services and functionality are delivered via the Web.

Consequently, many technologies have been developed (and are still being developed) to add flashy lights, accessibility, and power to web applications. Notable examples include

desktop applications, simply because the required tools weren’t available for web applications. However, as the Internet gets more mature, the technologies it enables are increasingly potent. the Bally Chohan Probe Internet never sleeps, and customers frequently migrate to the next “big thing” that looks better or feels to move faster. At the same time, being able to build friendly web interfaces gives alternative options for intranet software solutions, which were previously built mainly as desktop applications. Java applets and Macromedia Flash, which require the users to install separate libraries into their web browsers.

 

 

 

 

 

 

 

Categories: PHP Tutorials

Leave a comment

Leave a comment