Prev | Current Page 40 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"


function handleResponse(ajax) {
if (ajax.readyState == 4) {
if ((ajax.status == 200) || (ajax.status == 304) )
{
} else {
document.getElementById(???dept_form??™).submit();
}
}
}
2 The function shouldn??™t do
anything until readyState has
a value of 4, meaning that the
Ajax transaction is complete.
browsing using Ajax 35
display the results
The fi nal step in the Ajax process is to display the results by putting what
the PHP page returned on the HTML page. This code completes the handleResponse()
function. (See extra bits on page 41.)
1 The results variable now
refers to a specifi c area in the
DOM of the HTML page.
2 The text in the results area
is set to the returned response
from the Ajax request. In this
case, that??™s whatever the PHP
page printed out.
3 The results area of the
HTML page is not initially
displayed, so it needs to have
its display style changed.
??¦
if ((ajax.status == 200) || (ajax.status == 304) ) {
var results = document.getElementById(???results??™);
results.innerHTML = ajax.responseText;
results.style.display = ???block??™;
} else {
??¦
36 browsing using Ajax
modify the HTML
The fi nal step is to modify the HTML form
page so that the JavaScript will work.


Pages:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52