Datasheet

Chapter 1: AJAX Technologies
14
displays the login dialog box, and sets the display property of this DOM element’s style property to
none to hide the dialog box:
var credentials = document.getElementById(“credentials”);
credentials.style.display=”none”;
Next, readyStateChangeCallback invokes the getElementById method again, this time to return a
reference to the table DOM element that displays the server data, and sets the
display property of this
DOM element’s
style property to block to show this DOM element:
var employeeinfotable = document.getElementById(“employeeinfo”);
employeeinfotable.style.display=”block”;
Then, it invokes the responseText property on the XMLHttpRequest object to return a string that con-
tains the server data:
var response = request.responseText;
Keep in mind that the server data is in the following format:
Shahram|Khosravi|22223333|Some Department|
The next order of business is to deserialize an employee object from the server data. The following
excerpt from Listing 1-2 defines the
employee class:
window.employee = function window$employee(firstname, lastname,
employeeid, departmentname)
{
this.firstname = firstname;
this.lastname = lastname;
this.employeeid = employeeid;
this.departmentname = departmentname
}
As you can see in the following excerpt from Listing 1-2 , the readyStateChangeCallback function
invokes a JavaScript function named
deserialize :
var employee = deserialize();
This deserialize JavaScript function encapsulates the logic that deserializes an employee object from the
server data (described in more detail later). This logic is what is referred to as the Serializer in Figure 1-2 .
Next, the
readyStateChangeCallback function uses DHTML to update the relevant parts of the page
with employee information in the
employee object. First, it calls the getElementyById method on the
document object to return a reference to the <span> DOM element with the id HTML attribute of
c01.indd 14c01.indd 14 8/20/07 5:40:08 PM8/20/07 5:40:08 PM