Reputation: 49
My script does not work properly with Internet Explorer. The problem is that the 'data' (JSON.stringify (data);) is not updated with the new values after the script has been run once, it updates the div's with the same values as the first time it was run. I am a newbie when it comes to js, have no idea how to solve this. Grateful for help!
function ful() {
$.ajax({
url: 'api.php',
data: "",
dataType: 'json',
success: function(data) {
var imp = "";
var imps = new Array();
var set = new Array();
var div1, div2, div3, div4, tmp, hum, tid = "";
var temp = "";
var humi = "";
imp = JSON.stringify(data);
var values = imp.split(',');
var i = 0;
var y = 0;
for (var x = 0; x < values.length; x++) {
imps[y] += values[x];
i++;
if (i == 4) {
y++;
i = 0
}
}
for (var x = 0; x < imps.length; x++) {
div1 = "impid" + x;
div2 = "temp" + x;
div3 = "hum" + x;
div4 = "tid" + x;
set = imps[x].split('"');
tmp = set[9];
hum = set[13];
tid = set[17];
for (var y = 0; y < tmp.length; y++) {
temp += tmp[y];
if (y == 4) break;
}
for (var y = 0; y < hum.length; y++) {
humi += hum[y];
if (y == 4) break;
}
document.getElementById(div1).textContent = "ID : " + set[5];
document.getElementById(div2).textContent = "Temprature : " + temp + " °C";
document.getElementById(div3).textContent = "Humidity : " + humi + " %";
document.getElementById(div4).textContent = tid;
temp = "";
humi = "";
tmp = "";
tid = "";
hum = "";
}
}
});
setTimeout(ful, 6000)
}
$(ful);
Upvotes: 1
Views: 139
Reputation: 316
Internet Explorer caches ajax requests.
A simple workaround is to simply add a timestamp to the end of your request, forcing IE to get a new one. Jquery does this automatically for you when specifying the cache
parameter with false
:
$.ajax({
url: 'api.php',
data: "",
dataType: 'json',
cache: false,
success: ...
For other options, check out this post: https://devcentral.f5.com/blogs/us/fixing-internet-explorer-amp-ajax#.UcIVBZyiVSQ
Upvotes: 3