ajax创建
ajax对象创建和使用
//创建ajax对象
function createXMLhttp(){
var xmlhttp;
if(window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if(!xmlhttp){
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}
}
//发送请求
function request(){
xmlhttp.open("GET","test1.txt",true);
xmlhttp.send();
xmlhttp.onreadystatechange = callback();
}
//回调函数
function callback(){
//readyState:4代表完成状态。status:200代表成功状态
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText; //组织DOM结构
}
}
感谢您的阅读,您的支持是我写博客动力。

浙公网安备 33010602011771号