【发布时间】:2016-10-15 06:50:06
【问题描述】:
我在学校做一个项目,我需要控制用户有权访问其中一个页面。所有功能都需要通过 Ajax。
我的问题在于 Ajax 的回调。挣扎了几天,但似乎无法解决它。如果我跳过 Ajax,它可以工作。但我需要让它与 ajax 一起工作。我不知道用什么作为回调,我尝试了很多解决方案,但都没有奏效。
无论会话如何,任何人都可以访问该页面。
jquery:
<script>
$(window).load( function checkUser() {
$.post('calling_check_staff.php',
function(data){
$(). html(data); // I think the problem is here?????
});
});
</script>
calling_check_staff.php
<?php
session_start();
include ("php-classes/classUsers.php");
// Calling the class User and controlling that the visitor is logged in
$user = new User();
if($user->loggedIn()) {
}
?>
PHP 类
public function loggedIn() {
// Control, accessed page via login page.
if(isset($_SESSION["username"]) && $_SESSION["username"] != null) {
} else { header("location:index.php");
} }
【问题讨论】: