Chapter 15

15.1

Fill in the blanks in each of the following statements:

a) Ajax applications use asynchronous requests to create Rich Internet Applications.

b) In Ajax applications, the XMLHttpRequests object manages asynchronous interaction with the server.

c) The event hander called when the server responds is known as a(n) callback function.

d) The innerHTML attribute can be accessed through the DOM to update an XHTML element’s content without reloading the page.

e) JavaScript’s XMLHttpRequest object is commonly abbreviated as XHR.

f) JSON is a simple way to represent JavaScript objects as strings.

g) Making a request to a different server is known as cross-site scripting (XSS).

h) JavaScript’s eval function can convert JSON strings into JavaScript objects.

i) A(n) try block encloses code that might cause an exception and code that should not execute if an exeption occurs.

j) The XMLHttpRequest object’s responseXML contains the XML returned by the server.

15.2

State whether each of the following is true or false.  If false, explain why.

a) Ajax applications must use XML for server responses.

False.  Ajax applications can use any textual based responses such as JSON.

b) The technologies that are used to develop Ajax applications have existed since the 1990s.

True.

c) The event handler that processes the response is stored in the readyState property of XMLHttpRequest.

False.  The readyState property only keeps track of the page request’s progress.  The event handler is stored in the onReadyStateChange property.

d) An Ajax application can be implemented so that it never needs to reload the page on which it runs.

True.

e) The responseXML property of the XMLHttpRequest object stores the server’s response as a raw XML string.

False.  If the response data has XML format, the XMLHttpRequest object parses it and stores it in a document object.

f) The Dojo toolkit (like most other Ajax libraries) provides functionality that enables you to manipulate the DOM in a cross-browser manner.

True.

g) An exception indicates successful completion of a program’s execution.

False. An exception is thrown when there is a problem with the program execution.

h) When the third argument to XMLHttpRequest method open is false, the request is asynchronous.

False.  It is asynchronous when it is true.

i) For security purposes, the XMLHttpRequest object does not allow a web application to request resources from servers other than the one that served the web application.

True.

j) The innerHTML property of a DOM element can be used to obtain or change the XHTML that is displayed in a particular element.

True.

15.3

Describe the differences between client/server interactions in traditional web applications and client/server interactions in Ajax web applications.

With traditional non-Ajax web applications, the client/server interactions happen in a completely synchronous manner.  This means that when a client requests a page, the server sends it.  When a client fills out a form, or portions of a form, the server doesn’t get to review the contents until the client submits all of it at once.  This causes the client to wait for the server response and all of the information gets completely reloaded.  In Ajax, the client/server interaction is asynchronous which give the feel of real desktop applications on a web page.  A user can interact with the objects on the page in a manner which fits them and the server gets the information as it is happening and can respond to it on portions of the page dedicated to the responses.

15.4

Consider the AddressBook application in Fig. 15.9.  Describe how you could reimplement the type-ahead capability so that it could perform the search using data previously downloaded rather than making an asynchronous request to the server after every keystroke.

One way that you could reimplement the type-ahead capability using previously downloaded data rather and making asynchronous requests to the server would be to parse the array that was created in the block of code for the function getAddress, where the JSON string was converted to an array.  The variable named firstLast should be a global variable that other functions may call for this purpose.

15.5

Describe each of the following terms in the context of Ajax:

a) type-ahead

Type-ahead uses asynchronous requests to send individual letters typed and returns data based on the letters being typed (form-completion, data correction, etc.) to make the use of a form field quick (DOM, JavaScript, JSON).

b) edit-in-place

Edit-in-place allows a user to change the contents of a form or page by changing the state of the data displayed from purely textual object on the page to an editable form with the same contents there to edit and save the changes to the server (DOM, JavaScript, CSS).

c) Partial page update

Partial page update are a part of callback functions (usually JavaScript) which process returned data from a server and only update the parts of the page the callback says to update.

d) Asynchronous request

Asynchronous requests are enabled by JavaScript or XMLHttpRequest object running in the background on a client computer currently loaded webpage.

e) XMLHttpRequest

Is an object that is created that sends and receives data via an “open” and “send” method.  Supported on most browsers.

f) “raw” Ajax

“Raw” Ajax uses JavaScript to send asynchronous requests to the server, then updates the page using the DOM.

g) Callback function

A callback function is a function that processes the data received from a server for an asynchronous request.

h) Same origin policy

This policy creates security so that scripts cannot run from another domain than the one that the website resides on.  This is also known as cross site scripting (XSS).

i) Ajax libraries

Ajax libraries are larger builds of several components to be used with web applications rather than web sites.

j) RIA

Rich internet applications are built to work more like a traditional desktop application than a web page.  The data sent and received works in an asynchronous manner to update the page as the user manipulates it.

15.6

The XML files used in the book-cover catalog example (Fig. 15.8) also store the titles of the books in a title attribute of each cover node.  Modify the example so that every time the mouse hovers over an image, the book’s title is displayed below the image.

15.6

15.7

15.8

News:

Working on Chapter 18