0

I'm using Prototype.js to send a post request to a Magento controller. The controller will response a Json data or a redirect e.g. $this->_redirect('*/*/billing'); The issue that it seems the Ajax cannot detect the redirect response. I need to "catch" it then handle the redirect action in JavaScript by using window.location = redirect_url; Please help me as I don't want a workaround solution such as modifying response behavior in the controller. Thanks so much!.

new Ajax.Request(orderSaveUrl, {
    method: 'post',
    parameters: params,
    onComplete: function (response) {
        window.console.log('success' + response);
    },
    onFailure: function (response) {
        window.console.log('failure' + response);
    }
});
0

The browser handles the HTTP redirect internally, but I think you can figure out what the final URL was by inspecting the ajax transport object.

new Ajax.Request(orderSaveUrl, {
    method: 'post',
    parameters: params,
    onComplete: function (response) {
        window.console.log('success' + response);
        window.console.log(response.transport.responseURL); // <=====
    },
    onFailure: function (response) {
        window.console.log('failure' + response);
        window.console.log(response.transport.responseURL);
    }
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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