簡體   English   中英

為什么Ajax調用后我的php類無法正常工作

[英]Why aren't my php classes working after an ajax call

當用戶未登錄時,這是我的index.php文件,它會加載登錄頁面,否則會加載應用程序

$user = new User();
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" type="text/css" media="screen" href="assets/css/master.css"/>
        <script src="assets/js/functions.js?<? filectime('assets/js/functions.js') ?>"></script>

        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

        <script src="assets/vendor/jquery-validation/jquery.validate.min.js"></script>
        <script src="assets/vendor/jquery-validation/additional-methods.min.js"></script>

        <link rel="stylesheet" href="assets\vendor\bootstrap\dist\css\bootstrap.css">
    </head>
    <body>
        <div class="main-wrapper container-fluid">
        <?
        if($user->isLoggedIn()) {
            include_once 'app/index.php';
        } else {
            include_once 'files/auth/login.php';
        }
        ?>
        </div>
    </body>
</html>

這是在用戶未登錄時加載的login.php文件

 <div class="login-card">
    <form id="sign-in-form">
        <h2>Sign in</h2>
        <div class="form-group">
            <input type="text" name="username" required class="form-control" placeholder="Username">
            <input type="password" name="password" required class="form-control" placeholder="Password">
            <button type="submit" class="btn btn-primary btn-lg btn-block">sign in</button>
        </div>
    </form>
</div>
<div class="login-links">
    <a href="" id="register-link">Create an account</a>
    <a href="" class="grid-justify-end">Forgot password</a>
</div>

<script src="files/auth/js/login.js?<?= filemtime('files/auth/js/login.js') ?>"></script>

當用戶單擊創建帳戶時,將調用Ajax函數並將其加載到main-wrapper div中的注冊頁面,但是當將其加載到我的php類中時,用戶是否感到困惑? 並且index.php中的變量$ user也沒有防御

嘗試在注冊文件中包含包含用戶類的文件。

像這樣include 'path/to/users_phph_file/Users.php'; $user = new User(); include 'path/to/users_phph_file/Users.php'; $user = new User();

如果您的文件夾結構如下所示:

root -classes --users.php index.php

然后include 'classes/Users.php'; $user = new User(); include 'classes/Users.php'; $user = new User();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM