28 browsing using Ajax
call the function
The ajax.js fi le defi nes a function that creates an XMLHttpRequest object, but
it doesn??™t actually use that object. Another JavaScript fi le will do that for each
specifi c instance, like the HTML form already created. Use any text editing
application to make a new JavaScript document. (See extra bits on page 40.)
1 The fi rst line tells the Web browsers to
run the init() function after loading the
entire page. The init() function sets up
all the Ajax activity.
2 The init() function calls the
getXMLHttpRequestObject()
function to get a valid, browserspecifi
c object.
3 The init() function
then checks to see if the
ajax variable has a valid
value. With supported
browsers, ajax will be an
XMLHttpRequest object.
With nonsupported
browsers, ajax will have
a value of false, and this
conditional will be false.
window.onload = init;
function init() {
var ajax = getXMLHttpRequestObject();
if (ajax) {
} // End of ajax IF.
} // End of init() function.
browsing using Ajax 29
set up the Ajax
Now the JavaScript should
tell the browser what actions
should be taken when certain
events occur.
Pages:
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47