-2

this is my javascript function :

<script>
   function text() {
      var i = new Array();
      {% for content in table %}
         i[{{content.id}}]= document.getElementById('checkbox{{content.id}}').checked;
      {% endfor %}

      return i;
   }
</script>

as you can see I have some django template code in It. how to prevent caching of my script ?

I see this but It didn't solve my problem !

Community
  • 1
  • 1
nim4n
  • 1,813
  • 3
  • 21
  • 36
  • What exactly is being cached here? – Daniel Roseman Sep 10 '13 at 13:16
  • the value of i . I have a dajaxice function that update this template content .the problem is after ajax this script is cached by browser but I want to Update It . – nim4n Sep 10 '13 at 13:20
  • let me describe I have a table of content that need to be update each 5 second and I have a select box for each of this content. the problem is when a user select one of this checkbox after ajax this select is gone. so I want to use js for handle this problem if user select a content . the js script is in the template that render by ajax each time. – nim4n Sep 10 '13 at 13:42

1 Answers1

0

I'm not sure I've understood properly, but as far as I can tell this has nothing to do with caching: it is a matter of understanding when templates are rendered vs when scripts are executed.

This script is contained in a template. That template is rendered on the server side. Therefore, the script will be generated - and sent to the browser - with the values of content as they were at that point.

If you have an Ajax function which later updates something in the HTML page, this script will not care at all, because you have done nothing to update it - again, the values in the script were hard-coded when the template was sent to the browser.

You probably don't want to do it this way at all. Instead, you should find or define a parent element that contains all the checkboxes - a div or table row, for example - and then dynamically iterate through all descendants of that element to find the value of any checkboxes. You can then call this script from your Ajax function to update the values when the content changes.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895