ajax引擎对象的属性方法事件、及其get、post传参

XMLHttpRequest对象(即Ajax对象)的属性,方法,事件
事件
onreadystatechange: “请求状态”改变监听器,每当readyState属性的值发生变化时,该监听器上绑定
的函数将会执行

属性
readyState: “请求状态”,通过0,1,2,3,4这5个数字表示这次请求的状态,当该值变为4时,表示响应完成
          status:“http状态码”             200            404                          500
          statusText:“http状态描述” OK        Not Found        Internal Server Error
          responseText:服务器返回普遍文本信息
          responseXML:服务器返回的XML数据(仅作了解)

方法
open(method,url,async):表示创建一个Http请求;
      参数:
               method:表示请求方式(get/post)
               url:表示请求的路径
               async:表示是否异步请求(true/false)


send(param):发送http请求
          参数:
                  param:表示post请求发送的请求数据


setRequestHeader(key,value):设置请求头,必须在open方法和send方法之间
         如果我们希望通过post方式发送数据,需添加这样一个请求头:
         xhr.setRequestHeader("content-type","application/x-www-form-urlencoded")
        参数
               key:请求头的键
               value:请求头的值

get方式传参
xhr.open("get","getdata?name=zhangsan&age=18",true);
xhr.send();

post方式传参
xhr.open("post","getdata",true);
xhr.setRequestHeader("content-type","application/x-www-form-urlencoded")
xhr.send("name=lisi&age=18");

原文地址:https://www.cnblogs.com/su-chu-zhi-151/p/11220608.html