HTML and CSS Reference
In-Depth Information
Creating the Request Object—“ajaxCreateRequest.js”
EXAMPLE 18.4
/* Check browser type and create ajax request object
Put this function in an external .js file and use it for your
Ajax programs */
function CreateRequestObject() {
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
// Create the object
}
catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
return false;
}
}
}
return ajaxRequest;
} //End function
The Server-Side PHP Script—“serverTime.php”
EXAMPLE 18.5
1 <?php
//Server side script to handle request
2
extract($_REQUEST);
3
echo "Welcome, $name!";
4
echo "<br />Time now is ", date("h:i:s A "),".";
?>
EXPLANATION
1
The PHP server-side file, called serverTime.php is located in the server's root di-
rectory (e.g., htdocs , www , etc.) and will be executed by the server. Its output will
be sent back to the browser and displayed in the div container defined in the
HTML document. To run this script, you must have an HTTP server and PHP in-
stalled. See XAMPP at http://sourceforge.net/projects/xampp/XAMPP for installing
the Apache and PHP.
Search WWH ::




Custom Search