您好,登錄后才能下訂單哦!
廢話不多說,直接上代碼。你會(huì)發(fā)現(xiàn),用了JQuery之后是如何簡單。
//后臺(tái)實(shí)例代碼 ashx文件(可替換為從數(shù)據(jù)庫中讀?。? public void Proce***equest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string name = context.Request.Params["name"].ToString().Trim(); if ("china".Equals(name)) { context.Response.Write("1");//1標(biāo)志login success } else { context.Response.Write("0");//0標(biāo)志login fail } }
//前臺(tái)實(shí)例代碼 aspx文件 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $("#test").live("click", function() { //alert(0); $.ajax({ type: 'POST', url: 'Handler1.ashx', data: { "name": $("#name").val() }, success: function(data) { if (1 == data) alert('login success'); else alert('login fail'); } }); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input type="text" name="name" id="name" /> <input type="button" name="test" id="test" value="validate" /> </div> </form> </body> </html>
分別在前臺(tái)aspx頁面和后臺(tái)ashx頁面中輸入如上代碼,就實(shí)現(xiàn)了一個(gè)超級(jí)簡單的Ajax登錄,很簡單吧?
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。