Ajax創建

          //1 創建對象
          var xmlHttp;
          function createXMLHttpRequest(){
              if(window.ActiveXObject)
                  xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
              else if(widow.XMLHttpRequest)
                  xmlHttp = new XMLHttprequest();
          }
          //2建立請求
              ♠
                var firstName = document.getElementById("firstName").value;
                var url= "9-3.aspx?"+ new Date().getTime();
                xmlHttp.open("GET",url+ "firstName=" + firstName ,ture)//ture表示異步 get方法在提交數據時候在queryString 中發送數據
              ♣
                  xmlHttp.open("POST",url);//第4步發送數據時候用xmlHttp.send(firstName)
          //3異步對象鏈接服務器
          xmlHttp.onreadystatechange = function(){
              if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
                  var responseDiv = document.getElementById("serverResponse");//xmlHttp.responseText服務器的返回并賦值
                  responseDiv.innerHTML = decodeURI(xmlHttp.responseText); //解碼
          }
          //4數據發送
          xmlHttp.send(null)
             2步驟當為post時候
                  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

          posted on 2012-05-16 11:43 youngturk 閱讀(246) 評論(0)  編輯  收藏 所屬分類: Ajax

          <2012年5月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 曲周县| 富川| 建水县| 崇文区| 大洼县| 乌拉特中旗| 阜平县| 沈丘县| 错那县| 唐海县| 灵璧县| 淅川县| 桂阳县| 定结县| 甘洛县| 南雄市| 洛阳市| 兰考县| 大宁县| 镶黄旗| 轮台县| 潼关县| 石泉县| 砀山县| 盐山县| 丰宁| 罗江县| 汤原县| 沿河| 蕲春县| 寿阳县| 阳春市| 永清县| 三明市| 团风县| 河源市| 宜宾县| 深水埗区| 霍山县| 梁山县| 南雄市|