lundi 29 décembre 2014

Refreshing server side includes


I am currently using a STM32F4Discovery as a webserver and as I have little experience with web design I have run into a little problem...


I am wondering if it is possible to refresh my server side includes



!--#tag--


without refreshing the whole page using



meta http-equiv="refresh" content="x"


every x seconds? I tried using xmlhttp.open and xmlhttp.send which seems to work (my firmware responds and updates SSI values) but the values on the web page do not change.


Any help would be great, thanks!


EDIT:


I am using this demo from Highcharts which provides me with the following javascript code:



$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});

$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {

// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var tmp = "<!--#t-->";
var tmp2 = tmp.replace("<!--","");
tmp = tmp2.replace("#t-->","");
var x = (new Date()).getTime(), // current time
y = parseFloat(tmp);//parseFloat(document.getElementById('txtinput').value);
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Caliper Data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;

for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: parseFloat(document.getElementById('txtinput').value)
});
}
return data;
}())
}]
});
});


});


and I have also added this function:



(function worker(){
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","data.shtml",true);
xmlhttp.send();
setTimeout(worker,1000);


})();


However my SSI tags still only update on a refresh or page load





Aucun commentaire:

Enregistrer un commentaire