我想在JavaScript中添加一些PHP,但是,我目前使用的那個不起作用,並且想知道您是否可以提供幫助。將PHP加入JavaScript
這是我到目前爲止有:
$(document).ready(function() {
setTimeout(function() {
$("body").addClass("ready");
}, 1700);
setTimeout(function() {
$(".splash h1").html("Hi <?php echo '$first_name'?>");
setTimeout(function() {
$(".splash h1").html("Welcome to your Profile");
}, 1500);
}, 900);
});
變量first_name
已定義和PHP頁面會顯示上完全正常。
這裏是PHP代碼
<?php
/* Displays user information and some useful messages */
session_start();
// Check if user is logged in using the session variable
if ($_SESSION['logged_in'] != 1) {
$_SESSION['message'] ='<br>You must be logged in before accessing that page!';
header("location: login.php");
}
else {
$title = $_SESSION['title'];
$first_name = $_SESSION['first_name'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
$school_name = $_SESSION['school_name'];
$class = $_SESSION['class'];
$school_admin = $_SESSION['school_admin'];
$position = $_SESSION['position'];
$active = $_SESSION['active'];
$staff = $_SESSION['staff'];
$grav_hash = md5("$email");
}
?>
''$ first_name''刪除引號 –
完成 - 仍然沒有工作,只能用彈出‘嗨’。 – Tom
你沒有在末尾添加';'bud – Samuel