in this example, you can see the generated HTML list. With each update, the script requests a data file (ajax / test.json) and again creates a list.
The generated file "ajax / test.json" is statically cached. But how can I avoid requesting this file with every update?
// source: jquery.com $.getJSON('ajax/test.json', function(data) { var items = []; $.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); }); $('<ul/>', { 'class': 'my-new-list', html: items. }).appendTo('body'); });
This one does not work :
list_data = $.cookie("list_data"); if (list_data == undefined || list_data == "") { $.getJSON('ajax/test.json', function(data) { list_data = data; }); } var items = []; $.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); }); $('<ul/>', { 'class': 'my-new-list', html: items. }).appendTo('body');
Thanks in advance!
Mr. B. source share