該例子實現的功能:通過點擊Button從服務器端獲取數據然後提示輸出...
Default.aspx
- <html>
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=big5" />
- <title></title>
- <script language="javascript" type="text/javascript">
- var request;
- function createRequest() {
- try {
- request = new XMLHttpRequest();
- } catch (trymicrosoft) {
- try {
- request = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (othermicrosoft) {
- try {
- request = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (failed) {
- request = false;
- }
- }
- }
- if (!request)
- alert("Error initializing XMLHttpRequest!");
- }
- function getCustomerInfo() {
- createRequest();
- request.open("get","aaa.aspx",true);
- request.onreadystatechange =updatePage;
- request.send(null);
- }
- function updatePage()
- {
- if(request.readyState==4)
- {
- if(request.status==200)
- {
- alert(request.responseText);
- }
- }
- }
- </script>
- </head>
- <body>
- <form runat="server" action="">
- <input id="Button1" type="button" value="button" οnclick="getCustomerInfo();"/>
- </form>
- </body>
- </html>
aaa.aspx.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class nameSpace08108_aaa : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Write("hello!");
- Response.End();
- }
- }