jquerymobile w/php登录表单

jquerymobile w/php登录表单,php,html,jquery-mobile,Php,Html,Jquery Mobile,我是使用jquery mobile和php的新手。提交后,我的登录表单上的submit按钮出现了一个小问题,它指向“home.php”页面,但url也没有指向home.php。(仍然是/login.php)。我怎样才能解决这个问题 <?php include 'core/config.init.php'; //include all sql connect,function etc. if(logged_in() === true) { header('Location:

我是使用jquery mobile和php的新手。提交后,我的登录表单上的submit按钮出现了一个小问题,它指向“home.php”页面,但url也没有指向home.php。(仍然是/login.php)。我怎样才能解决这个问题

<?php

include 'core/config.init.php';     //include all sql connect,function etc.
if(logged_in() === true)
{
    header('Location: home.php');   
}

if(empty($_POST) === false)
{

    $check_user = true;
    $check_pass = true;
    $username = $_POST['username'];
    $password = $_POST['password']; 

    if(empty($username) === true || empty($password) === true)
    {
        $error = 'You need to enter username and password!';
        $check_user = false;
        $check_pass = false;
    }
    else if(user_exists($username) === false )
    {
        $check_user = false;
    }

    $login = login($username, $password);

    if($login === false)
    {
        $error = 'Username/password is incorrect!'; 
        $check_pass = false;
    }
    else
    {
        setcookie("username", "$username", time()+1720000); 
        header('Location: home.php');
    }
}
//print_r($error);

?>

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <link rel="stylesheet" href="core/css/login.css" />

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script> 
    <script type="text/javascript" src="core/jquery/jquery-latest.js"></script>  
    <script src="core/jquery/login.js"></script>
</head>
<body>
        <div data-role="page" data-theme="a">
            <div id = "header-text-area">
                <span id= "header-text">Login</span>
            </div>
            <div data-role="content" style="padding: 15px">
                <form action="login.php" method="POST">
                    <div data-role="fieldcontain" class="ui-hide-label">
                        <input name="username" id="textinput1" placeholder="Username" value="test" type="text" />
                    </div>
                    <div data-role="fieldcontain" class="ui-hide-label">
                        <input name="password" id="textinput2" placeholder="Password" value="test" type="password" />
                    </div>
                    <div id = "submit-area">
                        <input type="submit" data-theme="b" value="Submit" id = "sub1"/>
                    </div>
                </form>

            </div>
        </div>
</body>

登录

每次呼叫后

header("Location: home.php");
您需要添加一行,如下所示:

exit();

这应该可以解决您的问题。

您需要将
数据ajax=“false”
添加到表单标记中。这将在不使用jquery mobile内置的Ajax导航的情况下将表单提交到您的操作URL。此外,您应该在表单操作中使用完整的URL。(jquery mobile有时会感到困惑)

这不是固定的。如果exit()有标头,则它不是必需的。错误,需要在标头之后调用
exit()
:这就解决了问题。请看我的答案。如果我坚持的话,很抱歉,但这解决了一个问题。也许不是迫在眉睫的问题。如果脚本继续并输出一些东西,重定向将永远不会发生。没问题:)阅读文档-有很多很酷的提示