06-07-2009, 05:03 PM
|
#6 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
Jason's suggestion if an example of AJAX
Code:
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
if (request.overrideMimeType) {
request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {request = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try {request = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
This chunk simply attempts to create a new XMLHttpRequest object which is use for asynchronous request.
Code:
if (!request) {
alert('There was an error in creating an XMLHTTP instance, please update your browser!');
return false;
} else {
request.onreadystatechange = function() { statusCheck(request); };
request.open('POST', 'yourProcessingPage.php', false);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", param.length);
request.setRequestHeader("Connection", "close");
request.send(param);
}
}
This chunk does the work. Setting proper headers and sending the actual request. From the onreadystate property we can see that statusCheck has been set to verify results.
Code:
function statusCheck(request) {
if (request.readyState == 4) {
if (request.status == 200) {
window.response=request.responseText;
} else {
alert('There was a problem with the request.');
}
}
}
This is statusCheck function which was set to check response and verify all went well if it did than use the returned data and if not alert the user.
|
|
|
|