11 April 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
OK, 我昨天说 Catalyst 的 redirect 和 Ajax 的那个不合拍。后来得到那边的提示。用这样的代码解决了。
Controller:
sub vote : Global {
my ( $self, $c ) = @_;

unless ($c->user_exists) {
#$c->res->redirect('/login');
$c->res->body(<<HTML);
<script>
top.location = '/login';
</script>
HTML
return 1;
}
TT files:
var myAjax = new Ajax.Updater('vote_result', url, {method: 'get', parameters: pars, evalScripts: true});


这里多了个 evalScripts: true 这样可以在 div 里运行返回的 javascript.
Yup, It's OK now. 但是我想 prototype.js 应该能自动处理 redirect 这样的 Location header.


blog comments powered by Disqus