愚僧

          贏與輸的差別通常是--不放棄

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            23 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks
          /* 參考 : http://www.w3school.com.cn/xmldom/dom_http.asp */
          /*
           * 獲取ajax對象
           
          */
          function getXmlHttpRequest(){
              var xhr = null;
              if(typeof(XMLHttpRequest) != 'undefined'){
                  xhr = new XMLHttpRequest();
              }else{
                  xhr = new ActiveXObject("Microsoft.XMLHttp");
              }
              return xhr;
          }

          /*
           * post方式請求
           
          */
          function post(url, queryString,fn){
              var xhr = getXmlHttpRequest();
              xhr.open('post',url,true);
              xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
              xhr.onreadystatechange=function(){
                  if(xhr.readyState == 4){
                      if(xhr.status == 200){
                          fn.apply(this,[xhr]);
                      }
                  }
              };
              xhr.send(queryString);
          }

          /*
           * get方式請求
           
          */
          function get(url,fn){
              var xhr = getXmlHttpRequest();
              xhr.open('get',url,true);
              xhr.onreadystatechange=function(){
                  if(xhr.readyState == 4){
                      if(xhr.status == 200){
                          fn.apply(this,[xhr]);
                      }
                  }
              };
              xhr.send(null);
          }

           /*
            * 測試
            
          */
          post("ajax","",function(xhr){
              alert(xhr.responseText);
          });
          posted on 2013-02-22 17:18 ywm 閱讀(106) 評論(0)  編輯  收藏 所屬分類: html & css & js
          主站蜘蛛池模板: 昌平区| 济宁市| 文昌市| 微山县| 安达市| 河东区| 盐边县| 抚顺市| 股票| 原阳县| 西安市| 鹤岗市| 黎平县| 紫云| 高要市| 天门市| 兴安县| 延安市| 曲麻莱县| 仲巴县| 彩票| 涿州市| 类乌齐县| 林西县| 达日县| 怀化市| 宜昌市| 微山县| 韩城市| 阳东县| 苏尼特左旗| 金湖县| 剑阁县| 宾阳县| 察哈| 松江区| 华容县| 石景山区| 东乡县| 龙川县| 咸阳市|