Home >Backend Development >PHP Tutorial >ajax creation code_PHP tutorial
ajax creation code
var http_request=false;
function send_request(url){//Initialization, specify processing function, function to send request
http_request=false;
//Start initializing the XMLHttpRequest object
If(window.XMLHttpRequest){//Mozilla browser
http_request=new XMLHttpRequest();
If(http_request.overrideMimeType){//Set MIME category
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE browser
Try{
http_request=new ActiveXObject("Msxml2.XMLHttp");
}catch(e){
try{
http_request=new ActiveXobject("Microsoft.XMLHttp");
}catch(e){}
}
}
If(!http_request){//Exception, creation of object instance failed
window.alert("Failed to create XMLHttp object!");ajax creation code
Return false;
}
http_request.onreadystatechange=processrequest;
//Determine the request method, URL, and whether to execute the next code synchronously
http_request.open("GET",url,true);
http_request.send(null);
}
//Function to process returned information
function processrequest(){
if(http_request.readyState==4){//Determine the object status
If(http_request.status==200){//The information has been returned successfully, start processing the information
Document.getElementById(reobj).innerHTML=http_request.responseText;
}
else{//The page is abnormal
alert("The page you requested is not normal!"); ajax creation code
}
}
}
function dopage(obj,url){
document.getElementById(obj).innerHTML="Reading data...";
send_request(url);
reobj=obj;
}