简单登录系统spa/php/mysql/jquery


simple login system spa/php/mysql/jquery

我正在尝试创建一个简单的登录系统-我已经得到了我的用户能够登录并看到他的个人资料页面。我试图使链接工作在login_success.php模板…现在它只是将"#"附加到url(因为我使用它作为占位符)。

下面是我的代码: js/application.js

$(document).ready(function() {
    $("#main").load("templates/indexforms.php", function () {
        $("#login").submit(function(e) {
            e.preventDefault();
            $.post("checklogin.php", $(this).serialize(), function() {
                $("#main").load("templates/login_success.php");
                $("#login").remove();
                $("#register").remove();
            });
        });
        $("#register").submit(function(e) {  
            e.preventDefault();
            $.post("checkreglogin.php", $(this).serialize(), function(){
                $("#main").load("templates/login_success.php");
                $("#login").remove();
                $("#register").remove();
            });
        });
    });

    $("#loginlinkdiv a").click(function(event) {
        event.preventDefault();
        $("#main").empty();
        $("#main").load("templates/logout.php");
    });
    $("#logoutlinkdiv a").click(function(event) {
        event.preventDefault();
        $("#main").empty();
        $("#main").load("templates/indexforms.php");
    });
});

模板/login_success.php

<?php
session_start();
if($_SESSION['username'] === null){
    header("location: ../index.php");
}
?>
<h1>Login Successful</h1>
<h2>Username: <? echo $_SESSION['username']?></h2>
<div id="logoutlinkdiv" >
    <a href = "#" >Log out</a>
</div>

我不明白为什么当我点击退出链接时没有任何反应

我认为这应该可以工作:

$(document).on("click", "#logoutlinkdiv a", function(e) {
e.preventDefault();
   alert('logout button clicked');
 });

及说明:http://bugs.jquery.com/ticket/11203