DANCE WITH JAVA

          開發出高質量的系統

          常用鏈接

          統計

          積分與排名

          好友之家

          最新評論

          最簡單的ajax實現

          <script type="text/javascript" language="javascript">

              
          var http_request = false;

              
          function makeRequest(url) {

                  http_request 
          = false;

                  
          if (window.XMLHttpRequest) // Mozilla, Safari,
                      http_request = new XMLHttpRequest();
                      
          if (http_request.overrideMimeType) {
                          http_request.overrideMimeType('text
          /xml');
                      }

                  }
           else if (window.ActiveXObject) // IE
                      try {
                          http_request 
          = new ActiveXObject("Msxml2.XMLHTTP");
                      }
           catch (e) {
                          
          try {
                              http_request 
          = new ActiveXObject("Microsoft.XMLHTTP");
                          }
           catch (e) {}
                      }

                  }


                  
          if (!http_request) {
                      alert('Giving up :( Cannot create an XMLHTTP instance');
                      
          return false;
                  }

                  http_request.onreadystatechange 
          = alertContents;
                  http_request.open('GET', url, 
          true);
                  http_request.send(
          null);

              }


              
          function alertContents() {

                  
          if (http_request.readyState == 4{
                      
          if (http_request.status == 200{
                          alert(http_request.responseText);
                      }
           else {
                          alert('There was a problem 
          with the request.');
                      }

                  }


              }

          </script>
          <span
              style
          ="cursor: pointer; text-decoration: underline"
              onclick
          ="makeRequest('test.html')">
                  Make a request
          </span>

          posted on 2007-09-10 23:00 dreamstone 閱讀(2973) 評論(2)  編輯  收藏 所屬分類: 片段腳本語言javascript

          評論

          # re: 最簡單的ajax實現 2008-07-31 14:59 moonandsun

          這個實現是干嘛用的,看不太懂。  回復  更多評論   

          # re: 最簡單的ajax實現 2008-09-30 10:27 流水涵清

          不錯,這個例子蠻經典,很直觀的ajax  回復  更多評論   

          主站蜘蛛池模板: 平阳县| 通江县| 洛扎县| 揭阳市| 彭泽县| 泰安市| 西林县| 灌南县| 共和县| 武陟县| 五原县| 西峡县| 西林县| 两当县| 开鲁县| 东平县| 义乌市| 丹巴县| 旺苍县| 神农架林区| 武平县| 虞城县| 宣城市| 依兰县| 新昌县| 屯留县| 临潭县| 防城港市| 龙岩市| 临泉县| 酉阳| 巴青县| 黄梅县| 香港 | 于田县| 长垣县| 通辽市| 舞钢市| 苏尼特左旗| 石林| 始兴县|