Prev | Current Page 39 | Next

Larry Ullman

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


browsing using Ajax 33
} else { // No employees.
echo ???

There are no employees listed
for the given department.

??™;
}
mysql_close($dbc);
} else { // Invalid department ID!
??¦
4 Print an error if no employees were
found in the given department.
print the employees (cont.)
5 Close the database connection.
6 Save this fi le as dept_results_ajax.php
and place it in the same directory on your Web
server as every other fi le.
34 browsing using Ajax
handle the response
The PHP page prints out the employees, but since Ajax is being used, this
printout will actually be returned to the original JavaScript. Add this new
function to the dept.js JavaScript fi le. (See extra bits on page 41.)
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.
3 If the status code is equal to
either 200 or 304, the returned
results should be fi ne to use.
4 If we didn??™t get a valid status
code back from the Ajax request,
we should formally submit the
form to the handling PHP page
(as if the Ajax layer didn??™t exist
at all).


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