API:
HTTPRequest.buildQuery(queryData)
Builds a query in the form of ?key=value&key=value... from an assocaitive array / hash table / whatever you feel like calling it today.
HTTPRequest.getXMLObject()
Gets a raw XMLHttpRequest object in a platform-agnostic way
HTTPRequest.genericRequest(method, uri, content, callback, fallback)
Performs a genericized HTTPRequest.
method:
should be "GET", "POST", "HEAD", orany other method your server handles.uri:
The page to pull. Any get/head style queries should be appended as they would be in your address bar.content:
String representing fully escaped form data for POSTing. Will be ignored if method is not POST. Comment if you believe this to be bad.callback / fallback:
Functions in the form of myFunc(xmlObject). These will be called if the request succeeds or fails, respectively.
HTTPRequest.GET / HTTPRequest.HEAD (uri, queryData, callback, fallback)
uri:
The page to pull. Please use the next parameter for GET/HEAD queriesqueryData:
Assocaitive array of query data.callback / fallback:
same as in genericRequest
HTTPRequest.POST(uri, queryData, formData, callback, fallback)
Similar to GET. formData is an associative array of form variables.
Now, for the code!
var HTTPRequest=Object();
if (window.location.toString().substr(0,5).toLowerCase()=="file:")
alert("XMLHttpRequest, cannot work\n"+
"from a local filesystem.\n"+
"Please upload your project to\n"+
"a webserver and try this again.");
HTTPRequest.buildQuery = function (query) {
var data="";
var first="?";
for (i in query) {
data+=first+escape(i)+"="+escape(query[i]);
first="&";
}
return data;
}
HTTPRequest.getXMLObject = function () {
if (typeof(XMLHttpRequest)!='undefined') return new XMLHttpRequest();
var ax=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP'];
for (var i=0; i