我使用 jQuery .load() 函数的特殊情况是在单击链接后将页面包含到我的站点中。我选择内联编写代码。我所拥有的是一个带有几个按钮的用户控制面板,这些按钮可以链接到您编辑信息的页面。我有一个用于密码,一个用于设置。我试图让这个工作,我将为每个循环编写一个以应用于我单击的任何更多链接。我的 php 文件如下所示:
<?php
include_once("template/main_site/core/init.php");
protect_page();
if (empty($_POST) === false) {
$required_fields = array('current_password', 'password', 'password_again');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields lighted red are required.';
break 1;
}
}
if (encryptBetter($_POST['current_password']) === $user_data['password']) {
if (trim($_POST['password']) !== trim($_POST['password_again'])) {
$errors[] = 'Your new passwords do not match';
}
if (strlen($_POST['password']) < 6 || strlen($_POST['password']) >= 32) {
$errors[] = 'Your new password must be less than 32 characters and more than 6 characters.';
}
} else {
$errors[] = 'Your current password is entered incorrectly.';
}
}
?>
<h1>Change Password</h1>
<?php
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
echo 'Your password has been changed!';
} else {
if (isset($_GET['force']) === true && empty($_GET['force']) === true) {
?>
<p>You must change your password now that you've requested.</p>
<?php
}
if (empty($_POST) === false && empty($errors) === true) {
change_password($session_user_id, trim($_POST['password']));
header('Location: changepassword.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action = "" method = "post">
<ul>
<li>
<label>Current Password</label>
<input required type = "password" name = "current_password" pattern=".{6,32}"/>
</li>
<li>
<label>New Password</label>
<input required type = "password" name = "password" pattern=".{6,32}"/>
</li>
<li>
<label>Repeat New Password</label>
<input required type = "password" name = "password_again" pattern=".{6,32}"/>
</li>
<input type = "submit" value = "change password"/>
</ul>
</form>
<?php
}
?>
我将此 php 文件包含在包含页面中。我还注意到,如果我使用 php include 包含 changepassword.php 页面,它将正确加载。我基本上想要与 php 的包含相同的东西,除了 jQuery 加载。
我登录的包含的 php 文件如下所示:
<div id="controls">
<ul>
<a id = "changepassword" href = "#login"><li>Change Password</li></a>
<a href = "#"><li>Edit Profile</li></a>
<?php if (is_admin()) { ?><a href = "#admin"><li>Administrate</li></a><?php }?>
<a href = "logout.php"><li>Log out</li></a>
<div id = "panel"></div>
</ul>
</div>
<div id = "panel"><?php # include_once('template/main_site/includes/widgets/changepassword.php'); ?></div>
<script>
$('#changepassword').click(function() {
var phpFile = 'template/main_site/includes/widgets/' + $(this).attr('id') +'.php';
$('#panel').html('loading...').load(phpFile);
});
</script>
如果我是一个白痴,你可以拖我。我不在乎。如果它是 jQuery 中的安全块,请告诉我。我阅读了很多次 load 的文档,试图找出它为什么不起作用。如果我做不到,我希望这个社区告诉我,这样我就可以放弃了。我真的只是想要这些文件的实时包含。对我来说可能还有另一种解决方案。如果是这样,建议它。我可以尝试构建它。谢谢你。