It's a very simple example, and in the coming weeks I'll add further tutorials to expand this, such as a registration page, control panel to edit a user profile and an admin page to manage users. For the purpose of this entry however, i'll stick to a simple login feature.
If you are unfamiliar with AJAX, please see my AJAX search tool tutorial where I have explained how AJAX works. The JavaScript code used there, is very similar to that which I use in this example.
I will start by creating a function that creates and returns the XML HTTP object or ActiveX object that is required to implement AJAX. I have put this function in a separate file, so it can be accessed by different pages that use AJAX, instead of having to repeat the function body in every script.
JAVASCRIPT: -
function cl_xmlHttpObject () {
-
-
var xml_http_object;
-
-
try {
-
xml_http_object = new XMLHttpRequest();
-
} catch(e) {
-
try {
-
xml_http_object = new ActiveXObject("Msxml2.XMLHTTP");
-
} catch(e) {
-
try {
-
xml_http_object = new ActiveXObject("Microsoft.XMLHTTP");
-
} catch(e) {
-
//alert("ERROR: Your browser does not support AJAX.");
-
return false;
-
}
-
}
-
}
-
-
return xml_http_object;
-
-
}