--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
// view.html.php $script = "var ajaxurl = 'index.php?task=ajaxFunction&".JFactory::getSession()->getFormToken()."=1';"; // <-- this value, the token, is cached! $document->addScriptDeclaration($script); // ajax.js var request = new Request.JSON({ url: ajaxurl, onException: function(headerName, value) { // etc. } }); // controller public function ajaxfunction() { JRequest::checkToken('get') or die( 'Invalid Token!' ); // do other stuff }
I btw do check for a token but that code is a bit embedded in the extension. You'll add the token to the AJAX url http://....&yourtoken=1. Then at the PHP side you check for this token if it's 1.
If you enable the Joomla cache, the content is being cached and your var_dump doesn't represent the current value but the value which was calculated when the page was shown when it was cached. (Ok the Joomla caches behave differently, but just to make my point).I don't think the Joomla cache should specifically search for tokens and I'm aware of the issue. The only fix I'm aware of is disabling the Joomla cache for the specific page with a cache control plugin (see JED). If someone knows a better solution, please let us know.Btw I don't recommend to pollute the input variable with your token. You can use a function in your extension and calculate it within your extension or use a constant for it (DEFINE ...). Also if the token would change for every page refresh, how would you be able to check the token? It has to remain constant for a session. Indeed if you view it with a different browser, you'll have a different session and the token should change. But that couldn't happen decently when you cache that content.
Op woensdag 3 juli 2013 18:56:39 UTC+2 schreef Tim Kramer het volgende:
Hi TIm,
>> Are you suggesting that I create my own token check routine for my component rather than using the Joomla core token check?
Never mind regarding that $app->input issue, of course you'll need to get it from the input when you're using AJAX.Also it's better to use the form token, there are plenty examples in the Joomla source code:JFactory::getSession()->getFormToken();JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));This cache control plugin works, but is only J2.5 compatible:I don't think the System - Cache plugin could be managed with this plugin, I didn't test that.
>> I guess I'm just wondering (still) if there's any "standard" way to handle form tokens in Ajax on Joomla.
There's another topic where betweenbrian and some others are working on a new "standard" and easy Joomla AJAX way: