2013-10-03 38 views
0

我有用asp classic設計的這個jquery移動頁面。當我測試並嘗試登錄時,它會將我反彈回登錄頁面,而不是將我帶到已驗證用戶的索引頁面。這裏是我的代碼:用戶使用JQUERY和ASP登錄

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<!--#include file="../Connections/VT.asp" --> 
<% 
    ' *** Validate request to log in to this site. 
    MM_LoginAction = Request.ServerVariables("URL") 
    If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString) 
    MM_valUsername = CStr(Request.Form("username")) 
    If MM_valUsername <> "" Then 
     Dim MM_fldUserAuthorization 
     Dim MM_redirectLoginSuccess 
     Dim MM_redirectLoginFailed 
     Dim MM_loginSQL 
     Dim MM_rsUser 
     Dim MM_rsUser_cmd 

     MM_fldUserAuthorization = "" 
     MM_redirectLoginSuccess = "source.asp" 
     MM_redirectLoginFailed = "error.asp" 

     MM_loginSQL = "SELECT Username, Password" 
     If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization 
     MM_loginSQL = MM_loginSQL & " FROM dbo.Test_Register_Users WHERE Username = ? AND Password = ?" 
     Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command") 
     MM_rsUser_cmd.ActiveConnection = MM_VT_STRING 
     MM_rsUser_cmd.CommandText = MM_loginSQL 
     MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 70, MM_valUsername) ' adVarChar 
     MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 50, Request.Form("password")) ' adVarChar 
     MM_rsUser_cmd.Prepared = true 
     Set MM_rsUser = MM_rsUser_cmd.Execute 

     If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
      ' username and password match - this is a valid user 
      Session("MM_Username") = MM_valUsername 
      If (MM_fldUserAuthorization <> "") Then 
       Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value) 
      Else 
       Session("MM_UserAuthorization") = "" 
      End If 
      if CStr(Request.QueryString("accessdenied")) <> "" And true Then 
       MM_redirectLoginSuccess = Request.QueryString("accessdenied") 
      End If 
      MM_rsUser.Close 
      Response.Redirect(MM_redirectLoginSuccess) 
     End If 
     MM_rsUser.Close 
     Response.Redirect(MM_redirectLoginFailed) 
    End If 
%> 

<!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> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<link href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css" /> 
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script> 
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script> 
</head> 

<body> 
<div data-role="page" id="page"> 
    <div data-role="header"> 
    <h1>Header</h1> 
    </div> 
    <div data-role="content"> 
    <form id="form1" name="form1" method="POST" action="login_code.asp"> 
     <table width="325" border="0" cellpadding="3" cellspacing="3"> 
     <tr> 
      <td width="94">&nbsp;</td> 
      <td width="210">&nbsp;</td> 
     </tr> 
     <tr> 
      <td>Username</td> 
      <td><input type="text" name="username" id="username" /></td> 
     </tr> 
     <tr> 
      <td>Password</td> 
      <td><input type="text" name="password" id="password" /></td> 
     </tr> 
     <tr> 
      <td colspan="2"><div align="center"> 
      <input type="submit" name="button" id="button" value="Submit" /> 
      </div></td> 
     </tr> 
     </table> 
    </form> 
    </div> 
    <div data-role="footer"> 
    <h4>Footer</h4> 
    </div> 
</div> 
</body> 
</html> 
+2

如果我錯了,請更正我的錯誤,但不要在該頁面上的任何位置使用jQuery,或者使用Javascript。 (除了鏈接到它) – Nunners

+0

好的。所以請如何使認證工作? – blay

+0

@Nunners - 我刪除了ajax和jQuery標籤,因爲它們都不相關:) – Archer

回答

1

如果要連接到SQL數據庫,我不相信?是一個參數是正確的,你應該改變這些是@Username@Password,然後更改以下行是:

MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("Username", 200, 1, 70, MM_valUsername) ' adVarChar 
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("Password", 200, 1, 50, Request.Form("password")) ' adVarChar 

我看不到任何其他的問題,你的代碼,但我不太會用傳統的ASP所以我可能是錯的。嘗試添加日誌記錄步驟,以查看代碼執行的位置與您認爲應該在的位置相比較

+0

自從我使用傳統的ASP以來,這已經有一段時間了(謝天謝地),但是我也看不出它有什麼問題。這對我來說很好:) – Archer