public void ProcessRequest(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标志login success } else { context.Response.Write("0");//0标志login fail } }
2、前台实例代码 aspx文件
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="https://www.jb51.net/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 runat="server"> <div> <input type="text" /> <input type="button" value="validate" /> </div> </form> </body> </html>
分别在前台aspx页面和后台ashx页面中输入如上代码,就实现了一个超级简单的Ajax登录,很简单吧?
您可能感兴趣的文章: