seitime-frappe/js/wn/xmlhttp.js
Rushabh Mehta 0abfaf1180 version 2
2011-09-07 17:27:20 +05:30

36 lines
833 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, 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)
}
}
req.open('GET', url, async);
req.send(null);
// for sync
if(!async) {
wn.xmlhttp.complete(req, callback, url)
}
}
}