I have an ajax task to return a form token from my controller for use in ajax pages, so that subsequent ajax requests will have a token. It looks like this in the code:


and like this in the ajax request:


This works fine, until I use it in a multilingual site. In this case, the server returns a 303 error with the suggested redirect to


and the token never gets populated.

Is there something I need to do similar to JRoute::_() on the URL to ensure that the right URL is used and a 303 is not returned? (I did try JRoute but this didn't have any effect).


2 Answers 2


Instead of JUri::root() try to use this:

$baseUrl = JUri::getInstance()->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path'));
$baseUrl .'index.php?option=com_mycomponent&format=raw&task=ajax.tokenRequest'

See the reference.

Or simply do not use JUri::root().


First of all it would be nice to use the JSession::getFormToken() method to increse the security of your AJAX request. See also How to add CSRF anti-spoofing to forms

It is not very clear from your question, but it looks to me that you are not passing the language to the Request (like specifying the language parameter lang=de).

Also have a look into VirtualHosts for your development environment, so that you can have something like http://mycooljoomlasite.local instead of http://localhost/joomla3

  • I'm using the JSession::getFormToken() at the ajax endpoint to get the token. This is necessary because if you simply declare the variable in js (var token = JSession etc) it will be cached (if Joomla caching is on) and your token will always be invalid.
    – user101289
    Feb 3, 2015 at 20:43
  • That is interesting. Did you test it? Feb 4, 2015 at 7:11

Your Answer

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

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