Main Page

Practical Uses

}, 10);
} else {
alert(“Your browser doesn’t support HTTP requests.”);
Using this method, it’s now possible to perform POST requests in a variety of browsers using the same
var sURL = “”;
var sParams = “”;
sParams = addPostParam(sParams, “name”, “Nicholas”);
sParams = addPostParam(sParams, “book”, “Professional JavaScript”);, function(sData) {
alert(“Server sent back: “ + sData);
Once again, always supply the full URL when using this method.
Practical Uses
Although all this client-server communication stuff is really cool, it also has some practical applications.
You can, for example, create a search page that never unloads. It simply makes a request to get new data
for each new search you submit. This is the model used by’s new Web search engine, A9
After your first A9 search, you can choose to add images, movies, books, and other information to your
search results by clicking on the various options on the right of the screen. As you do, a new area in the
page opens up, and new search results are loaded using the hidden iframe technique discussed earlier in
the chapter.
Several Web sites use JavaScript client-server communication to provide search results. One such site,
the Bitflux blog (
), uses a XML HTTP request objects for its
bility. This cool technique uses the
event handler to detect what the user types into the
search box. For each new letter entered into the text box, the site does a search and displays its results in
a layer directly on the page, without ever reloading the page.
Another good use for this type of communication is to provide functionality that isn’t available in
JavaScript. For instance, you may want to validate some data the user has entered against a database.
Using the
event handler, you can make a request back to the database to determine if the value
is valid, and then present an error message to the user if is the data is not valid. The possibilities really
are endless.
Chapter 16
19_579088 ch16.qxd 3/28/05 11:42 AM Page 506

JavaScript EditorFree JavaScript Editor     Ajax Editor