PHP的Ajax和重定向 [英] PHP- Ajax and Redirect
问题描述
我有一个jquery Ajax请求发生在页面上。在PHP端我检查会话是否积极,做事。如果会话处于非活动状态,我想将用户重定向到另一个页面在PHP(头重定向)。我该怎么做了。
i have a jquery Ajax request happening on a page. On php side i am checking if the session is active and doing something. If the session is not active i want to redirect the user to another page in php(header redirect). how do i do it.
我知道如何去实现它在JavaScript(即如果session_fail然后改变了window.location但有东西,我可以在PHP做/ CakePHP的
I know how to achieve it in javascript(i.e if session_fail then change window.location but is there something that i can do in php/cakephp
推荐答案
如果我知道你要发生什么事情呢,这是我如何实现它。它的原型,而不是jQuery的,但它不应该带你长的翻译:
If I understand what you want to happen then this is how I'm implementing it. It's in Prototype instead of jQuery but it shouldn't take you long to translate:
new Ajax.Request('process.php', {
on401: function(response) {
var redirect = response.getHeader('Location');
document.location = redirect;
}
});
在你的PHP,输出如果会话处于非活动状态如下:
In your PHP, output the following if the session is inactive:
header('Location: http://example.com/login.php', true, 401);
exit;
这篇关于PHP的Ajax和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!