|
ÎÞˢеǼ´ó¼ÒÒ²Ðíûд¹ý£¬µ«ÊÇÒ»¶¨¶¼ÊÇÌý˵¹ýµÄ£¬ºÜÔçÒÔÇ°¾ÍÏëÓÃÕâ¸öС¼¼ÊõÔÚ×Ô¼º×öµÄСÏîÄ¿ÖÐÓÃÒ»°ÑÁË£¬µ«¶¼Ã»Óи¶³ö¹ýʵ¼ù£¬ÔÚÍøÉϲéҲûÓв鵽¾ßÌåÍêÕûµÄ´úÂ룬ÔÚÕâÀ½ñÌì²ËÄñ²ÌÒ²À´ÊÔÁËÒ»°Ñ£¬Ï׳óÁË£¬Ï£Íû¶Ô³õѧµÄͯЬÓеã°ïÖú
ºÃÁË£¬»¹ÊǺÍÒÔÇ°Ò»Ñù£¬ÏȽ¨Ò»¸öLogin.htmlÒ³Ãæ°É£¬ÓÃÓÚÌîдµÇ¼ÐÅÏ¢£¬È»ºóÔÙ½¨Ò»¸öDealData.aspxÒ³Ãæ°É£¨µ±È»£¬ÕâÀïÓÃÒ»°ã´¦Àí³ÌÐòÊÇ×îºÃµÄÁË£º*.ashx£©£¬ÓÃÀ´´¦ÀíÊý¾ÝÓõġ£
ÔÚlogin.htmlÒ³ÃæÖÐÆä´úÂëÈçÏ£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ: <head> <title>ÎÞˢеǼ</title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { //ÔªËØ°ó¶¨È«¾ÖajaxStartʼþ $("#divMsg").ajaxStart(function () { $(this).show(); //ÏÔʾspanÀïÃæµÄÄÚÈÝ }) //ÔªËØ°ó¶¨È«¾ÖajaxStopʼþ $("#divMsg").ajaxStop(function () { $(this).html("ÇëÇó´¦ÀíÒѾÍê³É£¡").hide(); }) $("#btnSure").click(function () {//µã»÷°´Å¥Ê¼þ var $name = $("#txtName");//»ñÈ¡µÇ¼Ãû var $pwd = $("#txtPwd");//»ñÈ¡ÃÜÂë if ($name.val() != "" && $pwd.val() != "") { //µ÷ÓÃLogin()·½·¨ Login($name.val(),$pwd.val()); } else { if ($name.val() == "") {//Èç¹ûµÇ¼Ãû²»Îª¿Õ alert("µÇ¼Ãû²»ÄÜΪ¿Õ£¡"); $name.focus();//»ñÈ¡½¹µã return false; } else { alert("ÃÜÂë²»ÄÜΪ¿Õ£¡"); $pwd.focus(); return false; } } }) }) function Login(name, password) { $.ajax({ type: "POST", //Êý¾ÝÇëÇóµÄ·½Ê½(post»òget)£¬Ä¬ÈÏΪget url: "DealData.aspx", //·¢ËÍÇëÇóµÄµØÖ·(ĬÈÏΪµ±Ç°Ò³) data: "action=Login&date=" + new Date() + "&name=" + name + "&pwd=" + password,//·¢Ë͵½·þÎñÆ÷µÄÊý¾Ý //µÇ¼³É¹¦ºó·µ»ØµÄÊý¾Ý success: function (data) { if (data == "True") {//¸ù¾Ý·µ»ØÖµ½øÐÐÅжϣ¨×¢Ò⣺Tureд³ÉtrueÓ¦¸Ã»á³ö´í°É£¡£© alert("µÇ¼³É¹¦£¡"); //window.location = "1.htm";ÒªÌøתµÄÒ³Ãæ } else { alert("µÇ¼Ãû»òÃÜÂë´íÎó£¡"); return false; } } }); } </script> </head> <body style="text-align:center"> <div>µÇ¼Ãû£º<input type="text" id="txtName" value="" /></div> <br /> <div>ÃÜ Â룺<input type="text" id="txtPwd" value="" /></div><br /> <div> <input type="reset" value="È·¶¨" id="btnSure" /> </div> <span id="divMsg" style="display:none;">ÕýÔÚ·¢ËÍÇëÇó......</span> </body> </html> ÔÚDealData.aspxÖУ¬Æäºǫ́´úÂëÈçÏ£º ¸´ÖÆ´úÂë ´úÂëÈçÏÂ: public partial class ManageData : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string name = System.Web.HttpUtility.UrlDecode(Request["name"]);//»ñÈ¡µÇ¼Ãû string pwd = System.Web.HttpUtility.UrlDecode(Request["pwd"]);//»ñÈ¡ÃÜÂë Response.Write(Login(name, pwd)); Response.End(); } private bool Login(string name, string pwd) { bool result = false; if (name == "С²Ë" && pwd=="123456") { return true; } return result; } } ºÃÁË£¬Í¯Ð¬£¬ÄãÒ²¸Ï½ôµÄÊÔһϰɣ¡ÎÞˢУ¬ÄãÒ²ÊÇ¿ÉÒÔµÄ! |
|