removeChild(results.lastChild);
}
var data = ajax.responseXML;
var names = data.getElementsByTagName(???name??™);
var departments = data.getElementsByTagName(???departmen
t??™);
var emails = data.getElementsByTagName(???email??™);
enabling an Ajax search 113
display the results
The results should be displayed like they are in the non-Ajax version. This is the
generated HTML from that page, which should be replicated. (See extra bits
on page 127.)
1 Before attempting to print the employees, we should confi rm that some
were returned by the PHP page. If at least one employee was returned in the
XML data, then names will have more than 0 elements in it. You can count
the number of elements in an array by referring to its length.
2 We??™ll need a slew of variables to add the values to the DOM.
??¦
var emails = data.getElementsByTagName(???email??™);
if (names.length > 0) {
var employee, span, name_node, dept_node, dept_
label, br, strong, a, email;
114 enabling an Ajax search
3 The for loop will access every item in the
names array. It counts from 0 (the fi rst item
in an array is at 0) to one less than the number
of items in the array.
Pages:
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104