为了让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>联合材料载于第一页:
$(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和发送警报。我没有收到我设置的任何警报或任何东西。我已经试过了我能想到的一切。:/
添加,我有用户名,用户化身,并可以注销我的外部页面以及所有。只是无法让登录生效。
发布于 2016-02-13 04:17:41
问题是,至少在一开始,我把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。我把它包括在表格里,没有检查它是否重要。
https://stackoverflow.com/questions/35329696
复制相似问题