Zend redirect()不支持AJAX请求?

Stu*_*ent 0 php redirect zend-framework

例如,我在Controller中有一个动作.

public function redirectnowAction() {
   $this->_redirect( '/module/controller/action' );
}
Run Code Online (Sandbox Code Playgroud)

当我以正常方式调用上述操作然后它成功地重定向到所需位置但是当我通过AJAX调用上述操作时,它不会重定向到所需的URL并且只在firebug中显示所需的页面内容.

AJAX的JS代码

jQuery('.AjaxLink').live( 'click', function(event) {
    event.preventDefault();
    // load the href attribute of the link that was clicked
    jQuery.getJSON(this.href, function(snippets) {
        for(var id in snippets) {
            // updated to deal with any type of HTML
            jQuery('#' + id).html( snippets[id] );
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

如何在AJAX请求后重定向到操作?

谢谢

Geo*_*ins 5

使用重定向时,您会向用户的浏览器发送标头以获取新位置的内容.

通常不会设置AJAX请求来处理此类重定向.他们只是发起请求,并返回响应.

最佳解决方案是重新组织代码,以便不需要重定向.如果无法消除重定向,则必须更新Javascript以识别重定向状态(例如,HTTP 301)并发起新请求.