Blogger Information
Blog 9
fans 0
comment 0
visits 8885
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Ajax基础
廖磊的博客
Original
728 people have browsed it

                                                                                          Ajax

一、创建ajax的对象,然后让对象来调用他本身的成员本身的属性

1.主流(火狐、Google、苹果、opera)浏览器

Var xhr= new XMLHttpRequest();

2.IE(6/7/8)浏览器创建

Var xhr=new ActiveXObject(“Microsoft.XHttp”); //最原始的方式
Var xhr=new ActiveXObject(“Msxml2.XMLHTTP.6.0”);

套路总结:

if(window.ActiveXObject){
Var xhr=new ActiveXObject(“Microsoft.XHttp”);
}
Var xhr= new XMLHttpRequest();

二、创建http协议请求

xhr.open(method,URL,flag);
Method: post / get
URL:请求的URL地址
Flag:true(异步交互) false(同步交互) 
Eg:  
① xhr.open("get","ajax.php",true);
xhr.send(null); //发送http协议请求
 
② xhr.open(“post”,”ajax.php”,true);
Xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
Xhr.send(data); //发送http协议请求

四、最大程度感受状态信息

xhr.onreadystatechange=function () {
   if (xhr.readyState==4  &&  xhr.status==200){
        //alert(xhr.responseText);
        document.getElementsByTagName("div")[0].innerHTML = xhr.responseText;
    }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post