XMLHttpRequest 对象

80477204 2015-03-23

一般都是忽略ie6以下的低版本浏览器,如果做到兼容性如下:

var request;
if(window.XMLHttpRequest){
    request= new XMLHttpRequest();//ie7+,ff,chrome,opera,safari.
}else{
    request = new ActiveXObject("Microsoft.XMLHTTP");//ie5 6}

语法:

open(method,url,async);
//method请求方式不区分大小写,url相对绝对地址都可,async默认true异步,false同步
send(string);

发送请求:

request.open("get","get.php",true);
request.send();

request.open("post","create.php",true);
//setRequestHeader 设置头部信息,必须要写在 open()和sent()的中间,否则抛出异常
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");   
request.send("name=wjy&sex=female");

相关推荐

80477204 / 0评论 2016-01-28