Prev | Current Page 37 | Next

Larry Ullman

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


8 Save this fi le as dept.js and place it in the same directory
on your Web server as every other fi le.
ajax.open(???get??™, ???dept_results_ajax.php?did=??™
+ encodeURIComponent(did));
ajax.onreadystatechange = function() {
handleResponse(ajax);
}
ajax.send(null);
return false;
} // End of anonymous function.
} // End of DOM check.
} // End of ajax IF.
??¦
browsing using Ajax 31
begin the PHP page
A new PHP script will handle the Ajax request. It works exactly like
dept_results.php (which we created in the previous chapter) except
that it doesn??™t need to print the opening and closing HTML tags. Use
any text editing application to make a new PHP document.
1 The page starts by making sure that it receives a valid
department ID in the URL. For security purposes, assume
we don??™t have a valid department ID.
2 If a department ID was passed to this page in the URL,
type-cast it (force it to be an integer).
3 If the result is a positive integer, we can go ahead and
query the database.
4 If the result isn??™t a positive integer, print an error
message instead.


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