jquery - Caching of json files -


i have website have 13 links. when click link, different json file, displays different data.

one problem is, when json files updated, updates aren't reflected online until clear cache or view json file , refresh it.

the other problem is, json data appears first link click appears other links click.

any ideas how solve these issues?

jquery:

$('.school').on("click", function() {     var school = $(this).attr('school');     $.getjson( school + "/data.json", function( data ) {              $('.images').empty();                          $('.videos').empty();                           $('.field').empty();                           var location, enrollment, tuition, history, alumni, fact, prose;                          location = data.location;                          enrollment = data.enrollment;                          tuition = data.tuition;                          history = data.history;                          fact = data.fact;                          alumni = data.alumni;                          prose = data.prose;                           $('.location').html('<strong>location</strong>: ' + location );                          $('.enrollment').html('<strong>enrollment</strong>: ' + enrollment);                           $('.tuition').html('<strong>undergraduate tuition</strong>: ' + tuition);                           $('.history').html('<strong>history</strong>: ' + history );                           $('.fact').html('<strong>notable fact:</strong> ' + fact );                          $('.alumni').html('<strong>prominent alumni</strong>: ' + alumni );                          $('.prose').html(prose);         }); }); 

assuming can't change caching options on server, can fix making use of fact query strings attached urls cacheable. i'm setting _ date.now() links remain valid 1ms.

var school = $(this).attr('school'),     url    = school + "/data.json?_=" + date.now(); $.getjson(url, function(data) { /* ... */ }); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -