HTTPRequest.buildQuery(queryData)
HTTPRequest.getXMLObject()
HTTPRequest.genericRequest(method, uri, content, callback, fallback)
HTTPRequest.GET / HTTPRequest.HEAD (uri, queryData, callback, fallback)
HTTPRequest.POST(uri, queryData, formData, callback, fallback)
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<ax.length; i++)
try {
return new ActiveXObject(ax[i]);
}
catch (e) {}
return null;
}
HTTPRequest.genericRequest = function (
method,
uri,
content,
callback,
fallback) {
var xmlhttp=HTTPRequest.getXMLObject();
if (xmlhttp==null) {
if (!HTTPRequest.complainedLoudly)
alert("Your browser does not support\n"+
"XMLHttpRequest in any known form");
HTTPRequest.complainedLoudly=true;
return false;
}
xmlhttp.onreadystatechange=function () {
if (xmlhttp.readyState==4)
if (xmlhttp.status==200)
callback(xmlhttp);
else
fallback(xmlhttp);
}
if (method=="POST") {
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",postdata.length);
xmlhttp.setRequestHeader("Connection","close");
} else content="";
xmlhttp.open(method.toUpperCase(),uri,true);
xmlhttp.send(content);
return true;
}
HTTPRequest.GET = function (url, query, callback, fallback) {
return HTTPRequest.genericRequest(
"GET",
url+HTTPRequest.buildQuery(query),
"",
callback,
fallback);
}
HTTPRequest.HEAD = function (url, query, callback, fallback) {
return HTTPRequest.genericRequest(
"HEAD",
url+HTTPRequest.buildQuery(query),
"",
callback,
fallback);
}
HTTPRequest.POST = function (url, query, form, callback, fallback) {
return HTTPRequest.genericRequest(
"POST",
url+HTTPRequest.buildQuery(query),
HTTPRequest.buildQuery(form).substr(1),
callback,
fallback);
}