我在尝试获取 PHPBB 的外部登录以使用 AJAX 时遇到了一些问题。我不太确定我在这里错过了什么,所以这是我得到的:
.HTML:
<div id="dialogin" class="dialoghide" title="Loading...">
<form id="loginformadj" name="loginformadj" action="forum/ucp.php?mode=login" method="post" data-ajax="true" data-refresh="false">
<h3><a id="dialoglogin" href="forum/ucp.php?mode=login" data-ajax="true">Login</a> •
<a id="dialogregister" href="forum/ucp.php?mode=register" data-ajax="true">Register</a></h3>
<fieldset id="userinfo">
<label for="username">Username:</label>
<input type="text" name="username" id="username" size="10" title="Username" />
<label for="password">Password:</label>
<input type="password" name="password" id="password" size="10" title="Password" />
<label for="autologin">Log me on automatically<input type="checkbox" name="autologin" id="autologin" /></label>
</fieldset>
<fieldset class="submit-buttons">
<input type="submit" name="login" value="Login" />
<input type="hidden" name="redirect" value="./index.php" />
</fieldset>
</form>
</div>
页面上包含的JS:
$(document).ready(function() {
// handle the login form through ajax for phpbb
$('#loginformadj').on('submit', 'form', function(event) {
event.preventDefault();
var url= $(this).attr('action');
alert(url);
$.ajax({
url: url,
type: 'POST',
dataType: 'HTML',
data: new FormData(this),
processData: false,
contentType: false,
success: function (data, status) {
alert(data);
},
error: function (xhr, desc, err) {
console.log('error');
}
});
});
});
这是我使用 phpbb 会话和其他函数的另一个文件的页面顶部所必需的:
<?php
/*
* BEGIN PHPBB STANDARD PAGE SETUP
*/
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$website_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
//include($phpbb_root_path . 'includes/functions.' . $phpEx);
include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
/*
* END PHPBB STANDARD PAGE SETUP
*/
?>
窗体被拉入 jquery 对话框。它确实让我登录,然后立即将我重定向到 ./forum 的论坛索引,而不是使用 ajax 并发送警报。我没有收到我设置的任何警报或任何东西。我已经尝试了我能想到的一切。:/
另外,我有用户名,用户头像,也可以在我的外部页面上注销所有内容。只是根本无法让登录工作。
问题,至少在最初,是我把论坛提交检查称为jquery错误。
$(document).ready(function() {
// handle the login form through ajax for phpbb
$(document).on('submit', '#login', function(event) {
event.preventDefault();
var url= $(this).attr('action');
alert(url);
$.ajax({
url: url,
type: 'POST',
dataType: 'HTML',
data: new FormData(this),
processData: false,
contentType: false,
success: function (data, status) {
alert(data);
},
error: function (xhr, desc, err) {
console.log('error');
}
});
});
});
我还读到您需要在隐藏字段中使用 $user-> 数据调用 sid。我在表格中包含了它,并没有检查它是否重要。