用HTTP POST方式装入一个远程页面
返回值:XMLHttpRequest
参数:
Login登录前端代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Login Page</title> <mce:script src="jQuery.js" mce_src="jQuery.js" type="text/javascript"></mce:script> <mce:script language="javascript" type="text/javascript"><!-- $(document).ready(function(){ $("#btnLogin").click(function(){ Login(); }); }); function Login(){ if(Check()) { LoginSuccess(); } } function Check(){ if($("#txtUser").val()=="") { alert("The user isn't empty"); $("#txtUser").focus(); return false; } if($("#txtPassword").val()=="") { alert("The Password isn't empty") $("#txtPassword").focus(); return false; } return true; } function LoginSuccess(){ $.ajax({ type:"POST", url:"CheckLogin.aspx", data:{userName:$("#txtUser").val(),userPwd:$("#txtPassword").val()}, beforeSend:function(){$("#msg").html("logining");}, success:function(data){ $("#msg").html(decodeURI(data)); } }); } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div style="margin-left:32px;" mce_style="margin-left:32px;"> <a>User:</a><input id="txtUser" type="text" /> </div> <div> <a>Password:</a><input id="txtPassword" type="text" /> </div> <div id="msg"></div> <div> <input id="btnLogin" type="button" value="Login" /></div> </form> </body> </html>
checkLogin服务器端代码
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class checkLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string retVal = ""; string userName = Request["userName"]; string userPwd = Request["userPwd"]; if (userName == "ike" && userPwd == "123") { retVal = "Login is success"; } else { retVal = "Login is false"; } Response.Write(retVal); } } }
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP