需要手动刷新页面以显示登录时的用户名
Manual page refresh required to show user's name as logged in
我在 Apache/2.4.7 (Ubuntu) 服务器上有一个网站 运行,没有任何错误,我在上面安装了一个使用 CodeIgniter 2.1 的 PHP 脚本。 4 和 Bootstrap.
在页面顶部,登录框作为模式弹出窗口工作,但当有人尝试登录时,脚本会重新加载页面但不会显示已登录的用户名。仅在手动刷新页面可以让用户看到他们的名字。
一个多月以来,我一直在努力寻找解决方案,包括重新安装服务器和脚本、更改 .htaccess
文件、停止 memcached 等
我联系了脚本的所有者和 CodeIgniter 支持,他们告诉我这可能是一个过载 Ajax 问题。
因为我的脚本主要是 Ajax 并且除了登录之外它工作正常,是否可以用不同的方式登录?我怎样才能正确集成脚本?
这是我的登录函数(assets/js/custom.js
):
function login() {
var email = $('#loginForm [name="email"]').val();
var pwd1 = $('#loginForm [name="password1"]').val();
if (isEmpty(pwd1) || isEmpty(email)) {
alert(msg_required_fields);
return false;
}
$.post(base_url + 'main/login', { "email": email, "pwd1": pwd1 }, function(data, textStatus, xhr) {
if (data.error == 1) {
alert(data.msg);
}
if (data.error == 0) {
document.location = base_url + 'main/reload';
}
}, "json");
}
更新
注销功能也有同样的问题:
function logout()
{
$this->admin->deleteTable('online',array('iduser' => $this->session->userdata('id')));
$this->session->unset_userdata('id');
$this->session->sess_destroy();
if( $this->session->userdata('facebook') == '1')
redirect(base_url(),"main/facebook/logout");
else
redirect(base_url()."main/reload","refresh");
}
从逻辑上讲,document.location 对象应该是只读的(因为您不能更改文档的 URL;更改 URL 会加载一个新文档),因此为了安全起见,当您想要设置 URL.
时,您应该使用 window.location.href
所以你应该试试 window.location.href
What is the difference between document.location.href and document.location?
我在 Apache/2.4.7 (Ubuntu) 服务器上有一个网站 运行,没有任何错误,我在上面安装了一个使用 CodeIgniter 2.1 的 PHP 脚本。 4 和 Bootstrap.
在页面顶部,登录框作为模式弹出窗口工作,但当有人尝试登录时,脚本会重新加载页面但不会显示已登录的用户名。仅在手动刷新页面可以让用户看到他们的名字。
一个多月以来,我一直在努力寻找解决方案,包括重新安装服务器和脚本、更改 .htaccess
文件、停止 memcached 等
我联系了脚本的所有者和 CodeIgniter 支持,他们告诉我这可能是一个过载 Ajax 问题。
因为我的脚本主要是 Ajax 并且除了登录之外它工作正常,是否可以用不同的方式登录?我怎样才能正确集成脚本?
这是我的登录函数(assets/js/custom.js
):
function login() {
var email = $('#loginForm [name="email"]').val();
var pwd1 = $('#loginForm [name="password1"]').val();
if (isEmpty(pwd1) || isEmpty(email)) {
alert(msg_required_fields);
return false;
}
$.post(base_url + 'main/login', { "email": email, "pwd1": pwd1 }, function(data, textStatus, xhr) {
if (data.error == 1) {
alert(data.msg);
}
if (data.error == 0) {
document.location = base_url + 'main/reload';
}
}, "json");
}
更新
注销功能也有同样的问题:
function logout()
{
$this->admin->deleteTable('online',array('iduser' => $this->session->userdata('id')));
$this->session->unset_userdata('id');
$this->session->sess_destroy();
if( $this->session->userdata('facebook') == '1')
redirect(base_url(),"main/facebook/logout");
else
redirect(base_url()."main/reload","refresh");
}
从逻辑上讲,document.location 对象应该是只读的(因为您不能更改文档的 URL;更改 URL 会加载一个新文档),因此为了安全起见,当您想要设置 URL.
时,您应该使用 window.location.href所以你应该试试 window.location.href What is the difference between document.location.href and document.location?