1.XMLHttpRequest对象
(1)异步对象链接服务器
(i)创建对象
var xmlHttp;
function createXmlHttpRequest()
{
if (window.ActiveXObject) //IE浏览器
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
(ii)建立请求
xmlHttp.open("GET","请求的地址",true);// true代表异步请求,false为同步
(iii)onreadystatechange事件
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState==4 && xmlHttp.status==200)
{
do sth.
}
}
(iv)send发送
xmlHttp.send(null)