Try appending an random variable at the end of url.
loadCSV("daily.csv?q="+Math.random());
문제
I am using apache on a raspberry pi to host a page for viewing on an internal network. The page consists of an amcharts graph displaying data from a csv file. The csv file updates every minute. Is there a way of forcing the graph to update?
I've already tried the following methods: Using the meta tag in the html reload Using setTimeout in the javascript to force reload.
The first method didn't work, the second works in some browsers (but not IE, which is what I need it to work in!)
Basically, I need the browser to not cache the referenced csv file. Any suggestions much appreciated! I've included the js that references the csv file below, and can include the whole page if necessary.
Thanks
loadCSV("daily.csv");
});
function loadCSV(file) {
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
var request = new XMLHttpRequest();
} else {
// code for IE6, IE5
var request = new ActiveXObject('Microsoft.XMLHTTP');
}
// load
request.open('GET', file, false);
request.send();
parseCSV(request.responseText);
}
function parseCSV(data) {
//replace UNIX new lines
data = data.replace(/\r\n/g, "\n");
//replace MAC new lines
data = data.replace(/\r/g, "\n");
//split into rows
var rows = data.split("\n");
// loop through all rows
for (var i = 9; i < 19; i++) {
// this line helps to skip empty rows
if (rows[i]) {
// our columns are separated by comma
var column = rows[i].split(",");
// column is array now
// first item is date
var time = column[0];
// second item is value of the second column
var value = column[1];
// third item is in the fourth column
var value2 = column[5];
var value3 = column[3];
// create object which contains all these items:
var dataObject = {
time: time,
actual: value,
target: value2,
scrap: value3
};
// add object to chartData array
chartData.push(dataObject);
해결책
Try appending an random variable at the end of url.
loadCSV("daily.csv?q="+Math.random());