Ajax基礎學習(一)——學號驗證

來源:互聯網
上載者:User

 AjaxTest.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax Test.aspx.cs" Inherits="Ajax_Test" %></p><p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head runat="server"><br /> <title>Ajax Test</title><br /> <mce:script type ="text/javascript" ><!--<br />var xmlHttp;</p><p> function createXmlHttpRequest()<br /> {<br /> if(window.XMLHttpRequest)<br /> {<br /> xmlHttp=new XMLHttpRequest();</p><p> if(xmlHttp.overrideMimeType)<br /> {<br /> xmlHttp.overrideMimeType("text/xml");<br /> }<br /> }<br /> else if(window.ActiveXObject)<br /> {<br /> try<br /> {<br /> xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");<br /> }<br /> catch(e)<br /> {<br /> xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");<br /> }<br /> }<br /> if(!xmlHttp)<br /> {<br /> window.alert("你的瀏覽器不支援建立XMLhttpRequest對象");<br /> }<br /> return xmlHttp;<br /> }</p><p>//建立CheckUserName</p><p>function CheckNumber(number)<br />{</p><p> createXmlHttpRequest();</p><p> var url="Event.aspx?Number="+number ;</p><p> xmlHttp.open("GET",url,true);</p><p> xmlHttp.onreadystatechange=CheckNumberResult;</p><p> xmlHttp.send(null);</p><p>}</p><p>//建立使用者檢測的回呼函數</p><p>function CheckNumberResult()<br />{<br /> if(xmlHttp.readyState==4)//伺服器響應狀態<br /> {<br /> if(xmlHttp.status==200)//代碼執行狀態<br /> {<br /> if(xmlHttp.responseText=="true")<br /> {<br /> document .getElementById ("txt_Name").value="張三"</p><p> }<br /> else<br /> {<br /> document .getElementById ("txt_Name").value="查無此學號!"<br /> }<br /> }<br /> }<br />}<br />// --></mce:script><br /></head><br /><body><br /> <form id="form1" runat="server"><br /> <div><br /> 請輸入學號:<asp:TextBox ID="txt_Number" runat="server" onkeyup="CheckNumber(document.getElementById('txt_Number').value)"></asp:TextBox>(預設學號:001)<br /> <br /><br /> 姓名:            <asp:TextBox ID="txt_Name" runat="server"></asp:TextBox><br /> </div><br /> </form><br /></body><br /></html>

Event.aspx.cs

using System;<br />using System.Collections;<br />using System.Configuration;<br />using System.Data;<br />using System.Linq;<br />using System.Web;<br />using System.Web.Security;<br />using System.Web.UI;<br />using System.Web.UI.HtmlControls;<br />using System.Web.UI.WebControls;<br />using System.Web.UI.WebControls.WebParts;<br />using System.Xml.Linq;</p><p>public partial class Event : System.Web.UI.Page<br />{<br /> protected void Page_Load(object sender, EventArgs e)<br /> {<br /> if (Request.QueryString["Number"].ToString() == "001")<br /> {<br /> Response.Write("true");<br /> Response.End();<br /> }<br /> else<br /> {<br /> Response.Write("false");<br /> Response.End();<br /> }<br /> }<br />}

相關文章

聯繫我們

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