Datasheet

Chapter 1: AJAX Technologies
15
firstname , and assigns the firstname property of the employee object to the innerText property of
this DOM element to display the first name of the employee:
var firstnamespan = document.getElementById(“firstname”);
firstnamespan.innerText = employee.firstname;
Next, it calls the getElementyById method again, this time to return a reference to the <span> DOM
element with the id HTML attribute of
lastname , and assigns the lastname property of the employee
object to the
innerText property of this DOM element to display the last name of the employee:
var lastnamespan = document.getElementById(“lastname”);
lastnamespan.innerText = employee.lastname;
It then repeats the same process to display the employee’s id and department name:
var employeeidspan = document.getElementById(“employeeid”);
employeeidspan.innerText = employee.employeeid;
var departmentnamespan = document.getElementById(“departmentname”);
departmentnamespan.innerText = employee.departmentname;
As mentioned, the deserialize JavaScript function deserializes an employee object from the server data:
function deserialize(response)
{
var delimiter=”|”;
var responseIndex = 0;
var delimiterIndex;
delimiterIndex = response.indexOf(delimiter, responseIndex);
var firstname = response.substring(responseIndex, delimiterIndex);
responseIndex = delimiterIndex + 1;
delimiterIndex = response.indexOf(delimiter, responseIndex);
var lastname = response.substring(responseIndex, delimiterIndex);
responseIndex = delimiterIndex + 1;
delimiterIndex = response.indexOf(delimiter, responseIndex);
var employeeid = response.substring(responseIndex, delimiterIndex);
responseIndex = delimiterIndex + 1;
delimiterIndex = response.indexOf(delimiter, responseIndex);
var departmentname = response.substring(responseIndex, delimiterIndex);
return new employee(firstname, lastname, employeeid, departmentname);
}
The deserialize function basically contains the logic that knows how to parse a string with the follow-
ing format into an
employee object:
Shahram|Khosravi|22223333|Some Department|
c01.indd 15c01.indd 15 8/20/07 5:40:08 PM8/20/07 5:40:08 PM