0

i am using the controller_action_postdispatch_ajax_index_add observer. i wanted to redirect to another category in this event so my code is as follows

Mage::app()->getResponse()
           ->setRedirect(
               Mage::getUrl($category_model->getUrlPath())
           )
           ->sendResponse();

but their is no redirection from the observer to the category page.please help me

1 Answer 1

1

by the name of your event, I assume you are doing an ajax call and trying to redirect from that one to some page.
It doesn't work like that for ajax calls, because the call is a different request.
The redirect actually works, but you get as response the html from the category page you want to redirect to.
But that does not redirect the page that has made the ajax call.
You need to return a JSON like this:

{
    'redirect': 'your url here';
}

Then, change the js function that handles the response from the ajax call and check this:

if (response.redirect) {
    window.location = response.redirect;
}

this will make your page redirect to the url that you get from the response of the ajax call.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.