Ajax and caching issues

Permalink
Hi,

I have a question about using ajax to call a block controller method.
In my block's view.php i us the following code to call the LoadBanner action in the controller.

<script>
   $(document).ready(function(){
      $("#header_banner").load("<?= str_replace("&","&",$this->action('LoadBanner'))?>");
   });
   </script>


This works fine and the desired result occurs. When a block is cached the above scripts fails. I looked at the source code of the page and can see that the <?= str_replace("&","&",$this->action('LoadBanner'))?> code used to call the controller method has a token id number attached to it.

which looks like this:

$(document).ready(function(){
      $("#header_banner").load("/index.php?cID=1&stackID=132&bID=26873&btask=passthru_stack&ccm_token=1402506928:14983183ba225d29360db7ddad4a2637&method=LoadBanner");
   });


This code changes every new page load, making it impossible to cache blocks and therefore pages using this logic.

Can anyone shed some ligh as to how i can load a controller function without this ccm token so i can cache the pages ?

Thanks

 
JohntheFish replied on at Permalink Reply
JohntheFish
There is a block controller flag that enables/disables cache on post requests.
obaudains replied on at Permalink Reply
Thanks john, but isnt the action url and token created before the post is made..?

The page renders, the url is set, so it will need to create a new token each time the page is loaded before the ajax posts to the controller action..?
JohntheFish replied on at Permalink Reply
JohntheFish
OK, I see what you meant. In that case you need to set all the block controller flags to no block caching at all and make sure you don't use enforced full page caching on that page.

Also make sure your ajax request uses post. If it does a get, then it could also end up in the browser cache.

Alternatively, if security of the request is not paramount, you could put the ajax responder in a tool where you decide how much token checking you want to apply.