function request(url, method, data, callback) {
var http = new XMLHttpRequest;
if (!http)
return false;
var _data;
if (data != null && typeof data == "object") {
_data = [];
for (var i in data)
_data.push(i + "=" + encodeURIComponent(data[i]));
_data = _data.join("&");
} else {
_data = data;
}
method = method.toUpperCase();
if (method == "POST") {
http.open(method, url, true);
http.setRequestHeader("Method", "POST "+url+" HTTP/1.1");
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
} else {
if (_data)
url += (url.indexOf("?") == -1 ? "?" : "&") + _data;
_data = "";
http.open(method, url, true);
}
if (callback)
http.onreadystatechange = function() {
if (http.readyState == 4) {
http.onreadystatechange = function(){};
callback(http);
}
};
http.send(_data);
return http;
}
