Ajax學習筆記(1)

來源:互聯網
上載者:User

標籤:

 1 <head runat="server"> 2     <title>簡單的ajax調用</title> 3     <script type="text/javascript"> 4         function Ajax() { 5             var xmlHttpReq = null; 6             //IE5,IE6是以ActiveXObject引入XMLHttpRequest對象 7             //這個判斷是為了相容上述兩個版本的IE瀏覽器 8             if (window.ActiveXObject) { 9                 xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");10             }11             //XMLHttpRequest是window對象的子物件12             else if (window.XMLHttpRequest) {13                 xmlHttpReq = new XMLHttpRequest();14             }15 16             xmlHttpReq.open("GET", "AjaxServer.aspx", true);17             //XMLHttpRequest對象的readyState值改變值,會觸發onreadystatechange事件18             xmlHttpReq.onreadystatechange = function () {19                 //請求完成載入:readyState=420                 //HTTP狀態值為20021                 if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {22                     var resText = document.getElementById("resText");23                     //responseText是伺服器端返回的結果24                     //即AjaxServer.aspx後台返回的結果25                     resText.innerHTML = xmlHttpReq.responseText;26                 }27             };28             //使用GET方法提交,所以可以使用null作為參數調用29             xmlHttpReq.send(null);30         }31     </script>32 </head>33 <body>34     <form id="form1" runat="server">35     <input type="button" value="Ajax提交" onclick="Ajax();" />36     <div id="resText">37     </div>38     </form>39 </body>
View Code
1   public partial class AjaxServer : System.Web.UI.Page2     {3         protected void Page_Load(object sender, EventArgs e)4         {5             Response.Write("hello,Ajax!");6         }7     }8 }
View Code

 

:

Ajax學習筆記(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.