SimpleModal PHP 登录表单:如何在成功/失败时重定向
希望你能帮忙。这里有一点 jQuery/AJAX 新手。
我有一个基本的 SimpleModal 登录表单,可以从我的网站主页调用它。
login.js 调用 login.php 脚本来检查我的数据库中的用户凭据。
如果登录成功,我会设置一些会话变量,并且通常使用 header 命令将用户发送到他们的个人页面(或登录失败时的错误页面)。
例如。 header("位置:restricted/index.php");
我无法关闭模式登录表单并将父主页重定向到会员页面。 我通常会留下空白的模态方块,上面写着“谢谢”,
如果我尝试用模态关闭来关闭模态表单,
success: function (data) {
$('#login-container .login-loading').fadeOut(200, function () {
$('#login-container .login-title').html('Thank you!');
msg.html(data).fadeIn(200);
$.modal.close(); //have inserted this line
});
},
但我会留在主页上。 (用户在此阶段已登录,但尚未发生重定向)。
我已经研究这个问题一两天了。我查看了 WordPress 登录插件,但我一无所知。有什么想法吗?
Hope you can help. A bit of a jQuery/AJAX newb here.
I have a basic SimpleModal login form that may be called from the homepage of my site.
login.js calls the login.php script that checks my database for a user's credentials.
If the login is successful I set a few session variables and I usually use the header command to send the user to their personal page (or the error page on login failure).
eg. header("Location:restricted/index.php");
I can't get the modal login form to close and the parent homepage to redirect to the member page. I'm usually left with the blank modal square saying "Thank You"
If i try to close the modal form with
success: function (data) {
$('#login-container .login-loading').fadeOut(200, function () {
$('#login-container .login-title').html('Thank you!');
msg.html(data).fadeIn(200);
$.modal.close(); //have inserted this line
});
},
the modal closes but I am left on the homepage. (The user is logged in at this stage but the redirect has not happened).
I've been kicking this around for a day or 2. I had a look at the wordpress login plugin but I am none the wiser. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,重定向可能确实发生了,它只是发生在AJAX 请求内。当您进行重定向时,ajax 函数使用的 XmlHttpRequest 会透明地跟随它,因此返回到客户端的页面是
restricted/index.php
。我倾向于做的是在那个页面上添加一个标题,如下所示:然后使用
$.ajaxSetup()
:这样(除非您覆盖
complete
,否则此选项会保持打开状态)返回的请求到达restricted/index.php
(记住 XmlHttpRequest 实际上去了那里),它将获得一个标头,让客户端知道它需要重定向。Actually the redirect probably did happen, it just happened inside the AJAX request. When you do a redirect, the XmlHttpRequest that the ajax functions use transparently follows it, so then page that came back to the client is the
restricted/index.php
. what I tend to do is add a header on that page, something like this:Then look for the header, something like this using
$.ajaxSetup()
:This way (unless you override
complete
, it leaves this option open) when a request comes back that made it to therestricted/index.php
(remember the XmlHttpRequest actually went there) it'll get a header to let the client know it needs to redirect.