Prev | Current Page 90 | Next

Larry Ullman

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


2 Close the root XML element
to complete the XML output. No
need to use closing HTML tags!
3 Save this fi le as search_
results_xml.php and place it in
(you guessed it) the same directory
as everything else.
??¦
} // End of IF.
mysql_close($dbc);
} // End of $_GET[???last_name??™] IF.
// Complete the XML document.
echo ?????™;
?>
110 enabling an Ajax search
handle the response
The PHP page sends back XML data, which must be handled by the JavaScript.
Add this new function to the search.js JavaScript fi le. (See extra bits on
page 126.)
1 This JavaScript function is called
when the ajax object??™s readyState
value changes (see the init() function).
The function receives the ajax
object when called.
2 The function shouldn??™t do
anything until readyState has
a value of 4, meaning that the
Ajax transaction is complete.
3 If the status code is equal
to either 200 or 304, everything
worked fi ne and we can
use the returned results.
function handleResponse(ajax) {
if (ajax.readyState == 4) {
if ((ajax.status == 200) || (ajax.status == 304) )
{
enabling an Ajax search 111
prepare the page
1 The results variable now refers to a specifi c area in the
DOM of the HTML page.


Pages:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102