The code copy is as follows:
//javascript Object: ajax Object
//Created By RexLee
function Ajax(url,data){
this.url=url;
this.data=data;
this.browser=(function(){
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";//IE browser
}else{
return "other";//Other
}})();
};
Ajax.prototype={
get:function(){
var result;
var xmlhttp;
if(this.browser=='MSIE'){
try{
xmlhttp=new ActiveXObject('microsoft.xmlhttp');
}catch(e){
xmlhttp=new ActiveXObject('msxml2.xmlhttp');
}
}else{
xmlhttp=new XMLHttpRequest();
};
xmlhttp.onreadystatechange=function(){
result = xmlhttp.responseText;//Closure, this. attribute cannot be used
};
xmlhttp.open('GET',this.url+'?'+this.data,false);//true cannot crawl data, why?
xmlhttp.send(null);
return result;
},
post:function(){
var result;
var xmlhttp;
if(this.browser=='MSIE'){
xmlhttp=new ActiveXObject('microsoft.xmlhttp');
}else{
xmlhttp=new XMLHttpRequest();
};
xmlhttp.onreadystatechange=function(){
result = xmlhttp.responseText;//Closure, this. attribute cannot be used
};
xmlhttp.open('POST', this.url,false);//It must be set to false, otherwise the responseText cannot be crawled
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//In POST, this sentence must
xmlhttp.send(this.data);
return result;
}
};
//var a=new ajax('opp2.js','');
//alert('by GET//n'+a.get())
//alert('by POST//n'+a.post());
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
window.onload=function(){
document.getElementById("btn").onclick=function(){
var p=document.getElementById("t").value;
var a=new Ajax("phpOOP/getPage.php","page="+p);
document.getElementById("box").innerHTML=a.get();
};
}