// initialize the ajax request object
ajax = new Object();
ajax.response = null;
/******************************************************************************
*
* Ajax Request Function -
* Makes an AJAX server request and returns the results.
*
* Use the format:
* ajaxRequest(url, method, info);
* Where `url` is the address of the script
* eg. http://www.yourdomain.com/ajax.php,
* `method` is the request method
* eg. "POST" or "GET",
* and `info` is an array of values to be passed to the script
* eg. { name:'john', email:'you@yours.com' }
*
******************************************************************************/
ajax.request = function (url, method, info) {
if (typeof url == 'undefined') {
return false;
}
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (typeof info == 'undefined') {
xmlhttp.open(method, url, false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(null);
ajax.response = xmlhttp.responseText;
return true;
}
var query = '';
for (var i in info) {
query += '&' + i + '=' + info[i];
}
query = query.substring(1);
if (method == 'POST') {
xmlhttp.open("POST", url, false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(query);
ajax.response = xmlhttp.responseText;
} else if (method == 'GET') {
xmlhttp.open("GET", url + '?' + query, false);
xmlhttp.send(null);
ajax.response = xmlhttp.responseText;
}
}
/******************************************************************************
*
* Get Ajax Response Function -
* Gets the response from an ajax request.
*
******************************************************************************/
ajax.getResponse = function (reset) {
if (typeof reset == 'undefined') { reset = true; }
var response = ajax.response;
if (reset == true) {
ajax.response = null;
}
return response;
};