XMlHTTP ajax實現資料無重新整理調用

來源:互聯網
上載者:User

 實現功能:文字框失去焦點時,帶出其他相關資訊。
HTML:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
    <script  type ="text/javascript" language ="javascript" >...
   var XmlHttp=false;
function AjaxSet()
...{
    if (window.XMLHttpRequest)
        ...{
            XmlHttp = new XMLHttpRequest;
        }
    else
        ...{
            try
                ...{
                    XmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
                }
            catch(e)
                ...{
                    XmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
                }
        }
}
function AjaxSendServer()
    ...{
        AjaxSet();
        var UserID=document.getElementById("txtUserID").value;
        var url="DAL.aspx?id="+UserID;
        XmlHttp.onreadystatechange=updatepage;
        XmlHttp.open("GET",url,true);
        XmlHttp.send(null);
    }
function updatepage()
    ...{
        if(XmlHttp.readyState==4)
        ...{
            if(XmlHttp.status==200)
            ...{
                var reponse=XmlHttp.responseText.split(',');
                document.getElementById("txtName").value=reponse[0];
                document.getElementById("txtDepart").value=reponse[1];
                XmlHttp=false;
            }
        }
    }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type ="text" id="txtUserID" runat="server" onfocusout ="AjaxSendServer()" />
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtDepart" runat="server"></asp:TextBox>
        <asp:GridView ID="gvTest" runat="server" Width="483px" ></asp:GridView>
    </div>
    </form>
</body>
</html>

其中資料處理URL: DAL.aspx

protected void Page_Load(object sender, EventArgs e)
    ...{
        if (Request.QueryString[0].ToString() == "F5400171")
        ...{
          Service.WebService cDAL = new WebService();

            string sql = "select username,departno from userinfor where userid='"+Request.QueryString[0].ToString()+"'";

            string s =cDAL.GetStr(sql);

           // string s = "jiaxin,MIS";
            Response.Write(s);
            Response.End();
        }
    }

其中的資料訪問採用webservice實現,這裡不在累述~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.