2015-10-04 50 views
3

得到的值我使用這個代碼提交我的形式我使用JavaScript提交表單,但我不能在PHP頁面

$('.login-form input').keypress(function (e) { 
     if (e.which == 13) { 
      if ($('.login-form').validate().form()) { 
      //$("#login-form input").submit(); 
       // window.location.href = "check.php"; 
    $.post("check.php", $("#login-form input").serialize(),    function(data) { 
    window.location.href = "check.php"; 
     }); 
      } 
      return false; 
     } 
    }); 

我不能夠在check.php得到的值。請幫助我。我知道它是一個基本的東西,但我無法做到這一點。在此先感謝

這裏是我的PHP代碼

 <?php 
     session_start(); 
     include_once("Includes/db_connection.php"); 
     include_once("participant/welcome.php"); 
     include_once("admin/admin_login.php"); 
     include_once("staff/staff_login.php"); 
     include_once("lecturer/lecturer_login.php"); 
     include("Includes/location.php"); 
     //include("Includes/lecturer_data_dropdown.php"); 

     $username=$_POST["username"]; 
     $password=$_POST["password"]; 
     echo $username; 
     if($_POST["user_type"]=="participant") 
     { 
     participant($password); 
     } 
     elseif($_POST["user_type"]=="admin") 
     { 
     admin($username, $password); 
     } 
     elseif($_POST["user_type"]=="staff") 
     { 
     staff($username, $password); 
     } 
     elseif($_POST["user_type"]=="lecturer") 
     { 
     lecturer($username, $password); 
     } 

     ?> 

這裏我只需要用戶類型,用戶名和密碼登錄做出決定

+1

您使用'$ .post'(POST謂詞)方法,併發布立即重定向使用「GET」動詞的用戶,你期望什麼? – undefined

+1

我想重定向到該頁面並獲取check.php中的表單數據,我正在決定重定向。請幫幫我。我被卡住了 –

回答

2

我注意到你在你的代碼的一個部分引用$('.login-form')和另一個是$('#login-form')。如果您的表單實際上使用的是類而不是ID,則.serialize()方法將返回一個空數組。將其更新爲$('.login-form input')(注意週期而不是散列)。在jQuery選擇

更多信息:https://api.jquery.com/category/selectors/

1

試試這個我試過和它工作得很好:

var var_username=$("Id of input box for username").val(); 
var var_password= $("Id of input box for password").val(); 

$.post(URL, 
    { 
    username: var_username, 
    password: var_password 
    }, 
    success:function(data) 
    { 
     //your message here.. 
    } 
); 
相關問題