[英]javascript not compatible with IE
My script does not work properly with Internet Explorer. 我的脚本无法与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. 问题是在脚本运行一次后,'data'(JSON.stringify(data);)没有使用新值更新,它使用与第一次相同的值更新div跑。 I am a newbie when it comes to js, have no idea how to solve this. 当涉及到js时,我是新手,不知道如何解决这个问题。 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);
Internet Explorer caches ajax requests. Internet Explorer缓存ajax请求。
A simple workaround is to simply add a timestamp to the end of your request, forcing IE to get a new one. 一个简单的解决方法是简单地在请求结束时添加一个时间戳,迫使IE获得一个新的时间戳。 Jquery does this automatically for you when specifying the cache
parameter with false
: 当使用false
指定cache
参数时,Jquery会自动为您执行此操作:
$.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 有关其他选项,请查看以下帖子: https : //devcentral.f5.com/blogs/us/fixing-internet-explorer-amp-ajax#.UcIVBZyiVSQ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.