AJAX stands for Asynchronous JavaScript And XML.
With AJAX, your JavaScript can communicate directly with
the server, using the JavaScript XMLHttpRequest object. With this object, your
JavaScript can trade data with a web server, without reloading the page.
With AJAX, your JavaScript can communicate directly with
the server, using the JavaScript XMLHttpRequest object. With this object, your
JavaScript can trade data with a web server, without reloading the page.
<html>
<body><script
type="text/javascript">
function ajaxFunction(){
var xmlHttp;try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e) {
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp=new
ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not
support AJAX!");
return false;
}
} }} </script>
<form name="myForm">Name:
<input type="text" name="username"
/>
Time: <input type="text"
name="time" />
</form></body></html>
Explanation
First create a variable xmlHttp to hold the
XMLHttpRequest object.
Then try to create the object with XMLHttp=new
XMLHttpRequest(). This is for the Firefox, Opera, and Safari browsers.
If that fails, try
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP") which is for Internet
Explorer 6.0+, if that also fails, try xmlHttp=new
ActiveXObject("Microsoft.XMLHTTP") which is for Internet Explorer
5.5+.
If none of the three methods work, the user has a very
outdated browser, and he or she will get an alert stating that the browser
doesn't support
AJAX - Sending a Request to the Server
To send off a request to the server, we use the
open() method and the send() method.
The open() method takes three arguments. The
first argument defines which method to use when sending the request (GET or
POST).
The second argument specifies the URL of the
server-side script.
The third argument specifies that the request
should be handled asynchronously.
The send() method sends the request off to the
server