虽然现在AJAX控件和类库层出不穷。但这个基础知识还是值得整理收藏一下。
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
// do something
}else{
alert("Server Busy,Please try again later!");
}
}
}
xmlhttp.open("post",url); //url is a variable
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send("v1="+escape(v1)+"&v2="+escape(v2)+"&v3=" + escape(v3) );//v1,v2,v3 are variables
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
// do something
}else{
alert("Server Busy,Please try again later!");
}
}
}
xmlhttp.open("post",url); //url is a variable
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send("v1="+escape(v1)+"&v2="+escape(v2)+"&v3=" + escape(v3) );//v1,v2,v3 are variables