美文网首页
XMLHttpRequest对象

XMLHttpRequest对象

作者: 闷骚师兄 | 来源:发表于2016-07-17 10:11 被阅读0次
    1. XMLHttpRequest对象的创建
      var xhr=null;
      if(window.XMLHttpRequest){
      xhr=window.XMLHttpRequest;
      }
      if(window.ActiveXObject){
      xhr=window.ActiveXObject("Microsoft.XMLHTTP");
      }

    2. XMLHttpRequest发送请求
      open(method,url,async);
      send(str);
      ! xhr.open("POST","create.php",false);
      xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xhr.send("name=王二狗&sex=男");

    3. XMLHttpRequest取得响应
      responseText:获得字符串形式的相应数据
      responseXML:获得XML个税的响应数据
      status和statusText:以数字和文本形式返回HTTP状态码
      getAllResponseHeader:获取所有响应报头
      getResponseHeader():获取某个字符段的响应信息,需要设置参数
      3.1 readyState属性
      取值:0 1 2 3 4
      xhr.onreadyStateChange=function(){
      if(xhr.status==200 && xhr.readystate==4){
      callback(JSON.parse(xhr.responseText));
      }
      }

    相关文章

      网友评论

          本文标题:XMLHttpRequest对象

          本文链接:https://www.haomeiwen.com/subject/oegujttx.html