1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| function AJAX(loadingStr){
this.request=this.GetRequest();
this.strLoading=loadingStr;
}
//Add new methods to AJAX
AJAX.prototype.GetRequest=GetRequest;
AJAX.prototype.Loading=function(){};
AJAX.prototype.Loaded=function(){};
AJAX.prototype.Interactive=function(){};
AJAX.prototype.Complete=function(status,statusText,responseText,responseXML){};
AJAX.prototype.SendAndLoad=SendAndLoad;
AJAX.prototype.browser=navigator;
AJAX.prototype.Query=Query;
AJAX.prototype.Post=Post;
function Query(url,responseLabel){
var instance=this;
var method=(arguments.length>2)?argurments[2]:"GET";
document.getElementById(responseLabel).innerHTML=instance.strLoading;
instance.Complete=function(status,statusText,responseText,responseXML){
try{
document.getElementById(responseLabel).innerHTML=responseText;
}catch(e){
alert("Error in loading data");
}
}
instance.SendAndLoad(url,method);
}
function SendAndLoad(url){
var method=(arguments.length>1)?arguments[1]:"GET";
var instance=this;
var now=new Date();
if(url.split("?").length>1){
url+="&ext="+now.getSeconds()+Math.random()*300;
}else{
url+="?ext="+now.getSeconds()+Math.random()*300;
}
//alert(url);
instance.request.open(method.toUpperCase(),url,true);
instance.request.onreadystatechange=function(){
switch(instance.request.readyState){
case 1:
instance.Loading();
break;
case 2:
instance.Loaded();
break;
case 3:
instance.Interactive();
break;
case 4:
instance.Complete(instance.request.status,instance.request.statusText,instance.request.responseText,instance.request.responseXML);
break;
}
}
if(method.toLowerCase()=="post"){
instance.request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
var data=(arguments.length>2)?arguments[2]:"&tmpData="+Math.random()*100;
this.request.send(data);
}
function GetRequest(){
if(window.XMLHttpRequest){
this.request=new XMLHttpRequest();
return new XMLHttpRequest();
}else if(window.ActiveXObject){
var msxmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
for (var i = 0; i < msxmls.length; i++){
try{
this.request=new ActiveXObject(msxmls[i]);
return new ActiveXObject(msxmls[i]);
}catch (e){
alert(e);
}
}
}
throw new Error("Could not instantiate XMLHttpRequest");
}
//Post data to server
function Post(url,data,responseLabel){
var instance=this;
document.getElementById(responseLabel).innerHTML=instance.strLoading;
instance.Complete=function(status,statusText,responseText,responseXML){
document.getElementById(responseLabel).innerHTML=responseText;
}
instance.SendAndLoad(url,"POST",data);
} |
Partager