AJAX - The Complete Reference

(avery) #1

2 Pre-Ajax JavaScript Communications Techniques


B


efore there was a catchy moniker like Ajax, there were still many ways to communicate
to the server using JavaScript. Web developers are an ingenious lot and over the years
have demonstrated that just about any tag that can be set to reference a URL can be
employed for JavaScript-based communications duties. The most common techniques used
in the pre-Ajax world were image requests, inline frames, and the script tag. With the rise of
the XMLHttpRequest (XHR) object use in Ajax, some readers might deduce that the old
methods should be retired or that the communication patterns are different, yet such is not
the case. Interestingly, some very well-known Ajax-powered sites use these older techniques
to get around security limitations of the XHR object or provide backward compatibility.
Read on not only to get a solid foundation in JavaScript-based communication but also to
learn useful techniques that will resurface later.

One-way Communication


A simple use of remote JavaScript is to spawn a request to the server to indicate that some
event has happened, such as an error condition or a particular user activity like clicking
a link to visit another site. In these scenarios the request is considered one-way, as it may
not be important that a response be returned to the client.
As an example of one-way communication, consider a simple rating system. In this
scenario you will present the user with a set of choices to indicate their feelings about a
particular product, idea, page, or whatever you are interested in finding their opinion on.
The user interface for the rating system might range from a simple set of radio buttons

to more complex user interface widgets such as a slider

15


CHAPTER


http://www.ebooks.org.in

Free download pdf