2013-11-15 67 views
0

當我嘗試使用用戶名和密碼登錄到另一個頁面時,沒有任何反應只是頁面刷新。jQuery Mobile用戶登錄

<%@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 = "#page2" 
    MM_redirectLoginFailed = "error.html" 

    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 rel="stylesheet" href="themes/vtapp.min.css" /> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile.structure-1.3.2.min.css" /> 
<style type="text/css"> 
body,td,th { 
    font-family: "Myriad Pro"; 
    font-size: 14px; 
    color: #000; 
} 
</style> 
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> 
</head> 

<body> 
<div data-role="page" id="page"> 
<div data-role="content" data-theme="a"> 
    <form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>"> 
     <table width="284" border="0" cellpadding="3" cellspacing="3"> 
     <tr> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td>Enter Username and Password</td> 
     </tr> 
     <tr> 
      <td><input name="username" type="text" id="username" value="blay" /></td> 
     </tr> 
     <tr> 
      <td><input name="password" type="text" id="password" value="BBBBBB" /></td> 
     </tr> 
     <tr> 
      <td><div align="center"> 
      <input type="submit" name="button" id="button" value=" Sign In " /> 
      </div></td> 
     </tr> 
     </table> 
     <p>&nbsp;</p> 
    </form> 
    <div data-role="page" id="page2"> 
     <div data-role="header"> 
     <h1>Header</h1> 
     </div> 
     <div data-role="content">Welcome User</div> 
    </div> 
</div> 
</div> 
</body> 
</html> 

在檢查所有寫入的內容後,所有的代碼都是正確的。

+0

'#page2「'被稱爲另一頁嗎? –

+0

是#page2是同一頁上的另一頁 – blay

+0

也許我錯了,但response.redirect需要一個頁面,而不僅僅是一個散列。不應該是MM_redirectLoginSuccess = MM_LoginAction +「#page2」'? –

回答

0

Dreamweaver生成真正可怕的ASP代碼。我可以提供的最好的建議是你可以通過谷歌瞭解如何在Classic ASP中編寫登錄表單。有一個在這裏

http://www.w3schools.com/website/web_asp_login.asp

而且還有很多其他的。一旦你完成了,然後刪除所有Dreanweaver生成的垃圾,並用你自己的代碼替換它。

無論如何,看看你的頁面中的HTML我可以看到沒有邏輯決定是否顯示登錄表單或歡迎消息。嘗試一下沿線的

<% if Session("MM_UserAuthorization") = "" then %> 
    <form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>"> 
    (rest of your form here, I'm not going to copy it all) 
    </form> 
<% else %> 
    <div data-role="page" id="page2"> 
    <div data-role="header"> 
    <h1>Header</h1> 
    </div> 
    <div data-role="content">Welcome User</div> 
    </div> 
<% end if %> 
+0

我想要它做的是當它驗證用戶名和密碼是正確的,它應該帶你到#page2這將給你的歡迎信息 – blay

+0

MC ND所作的關於Response.Redirect的評論可能是有效的,並且MM_redirectLoginSuccess =「name-of-your-page.asp#page2」可能會將第17行更改爲值。看看你的代碼,雖然看起來你可以向下滾動到歡迎消息,無論你是否登錄。當然,你希望它只在用戶登錄時纔可用 – John