clankill3r
clankill3r

Reputation: 9583

How to clear the cache for JSON

I'm reading a JSON file with jQuery. If I update the file that .get() reads it still gets the old values when I read the newer file. Since I write and read the file every second, how can I solve this problem? Manually clearing the cache won't be a option.

function readEye() {

    $.getJSON('output.json', function(data){

        console.log(data);

    });

}

Upvotes: 3

Views: 10703

Answers (1)

Rafay
Rafay

Reputation: 31043

use $.ajaxSetup settings

$.ajaxSetup({
  cache:false
});

after that you can use your code like

function readEye() {
  $.getJSON('output.json', function(data){
    console.log(data);
  });
}

Upvotes: 5

Related Questions