seitime-frappe/js/wn/xmlhttp.js
2011-09-14 12:25:33 +05:30

37 lines
880 B
JavaScript

wn.xmlhttp = {
request: function() {
if ( window.XMLHttpRequest ) // Gecko
return new XMLHttpRequest() ;
else if ( window.ActiveXObject ) // IE
return new ActiveXObject("MsXml2.XmlHttp") ;
},
complete: function(req, callback, url) {
if (req.status==200 || req.status==304) {
callback(req.responseText);
} else {
alert(url +' request error: ' + req.statusText + ' (' + req.status + ')' ) ;
}
},
get: function(url, callback, args, async) {
// async by default
if(async === null) async=true;
var req = wn.xmlhttp.request();
// for async type
req.onreadystatechange = function() {
if (req.readyState==4) {
wn.xmlhttp.complete(req, callback, url)
}
}
var u = args ? (url + '?' + args) : url;
req.open('GET', u, async);
req.send(null);
// for sync
if(!async) {
wn.xmlhttp.complete(req, callback, url)
}
}
}