For example I have an action in Controller.
public function redirectnowAction() {
$this->_redirect( '/module/controller/action' );
}
When I call above action in normal way then it redirect successfully to desired location But when I call above action by AJAX then it does not redirect to required URL and only show desired page content in firebug.
JS code for AJAX
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] );
}
});
});
How to redirect to action after AJAX request ?
Thanks
You cannot do it directly, here’s what I’d do. In the action called via AJAX, include something like this:
This way, your AJAX call will receive a JSON object as a response. In jQuery’s
$.ajax()call, you can specify asuccessevent, e.g.: