0
votes

An ajax request calls a controller function within my MVC Component. And in this function there is a Joomla redirect at the end with

JFactory::getApplication()->redirect(JRoute::_($redirect_url, false));

The problem is, that the redirected page won't open! While debugging a session, I can see that the controller will initiate the redirect and the proper details will be sent to view.html.php. But the page, in this case it is a different view in tmpl, will not be open!

Is this because of the ajax call? Do I have to do something in the ajax success part?

1
It would be better if you can paste some more code like form,ajax and controller function.One way is that in controller you should sent back some response to ajax call and based on the response you decide to either redirect(through js) or do other task. - Irfan
jQuery(document).ready( function() { jQuery(".productorder").click(function (SetOrder) { var order = jQuery(this).find("#productnr").attr("value"); var formdata = new FormData(); formdata.append("productnr", order); jQuery.ajax({ type: "POST", dataType: "json", data: formdata, processData: false, contentType: false, url: "index.php?option=com_component&task=controller.function", success:function(result) { } }); }); }); - Perino
in the form I have several 'buttons'. These are not really buttons, they are images with href and onlick function, which are initialising the ajax call. Submit buttons would be prefered, but not possible, because I need to transfer one value (productnr). And each 'button' has its own product nr. So form submission can not be done, instead I make a jquery ajax call to address the controller function. But finally I need the redirect, which will normal be done, by the last statement in the controller function ->redirect(JRoute::_....) - Perino

1 Answers

1
votes

Yes, now I do the url preparation in the controller and send back the url to ajax.

$redirect_url = "index.php?option=com_mycomponent&view=my_view&layout=different_layout"

Ajax will do the redirect with the given url. window.location = result.data;

From there iam struggeling with the SEF part of Joomla to get a SEF friendly URL.