IE is not displaying text updated by Javascript
In my project I developing a web interface for the device. The device's time and name is updated on webpage using AJAX.
On first run, when a webpage is created(updated) the page is properly displayed by IE8 but on refresh/revisit, the time is displayed properly but device name text(which changes occasionaly) is absent. I am using innerHTML property to update the text.
I do not face this problem when I access pages on Google Chrome. I have also disabled cache using HTML header. The HTML header is as given below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
script:
function OnComplete (xmlDoc) {
/* ToDo: Add complete event here or remove method
xmlDoc contains the received XML Document */
try{
var txt="";
x = xmlDoc.getElementsByTagName("DateTime");
document.getElementById("idClock").innerHTML = x[0].firstChild.n开发者_运维百科odeValue;
x = xmlDoc.getElementsByTagName("TCOLOR");
document.getElementById("idClock").style.color = x[0].firstChild.nodeValue;
x = xmlDoc.getElementsByTagName("deviceNameType");
alert(x[0].firstChild.nodeValue);
document.getElementById("deviceName").innerHTML = x[0].firstChild.nodeValue;
x = xmlDoc.getElementsByTagName("ALARM");
var alarmImg = document.getElementById("idImgAlarm");
var value = x[0].firstChild.nodeValue;
switch(value){
case '0':
SetClassName( alarmImg, 'replace', 'hidden', 'inline' );
break;
case '1':
alarmImg.src = 'Alarm.gif';
SetClassName( alarmImg, 'replace', 'inline', 'hidden' );
break;
case '2':
alarmImg.src = 'Alarm_static.jpg';
alarmImg.className ="p4 pr10 f_r pointer inline";
break;
default:
alert("default");
break;
}
}catch(e){/*alert('ERROR\n'+ e);*/}
}
Sample XML:
<?xml version="1.0" encoding="ISO-8859-1"?><rtc><DateTime>2010-12-03 13:01:39 (UTC)</DateTime><TCOLOR>#0</TCOLOR><deviceNameType>AA1J1Q01A1, MYDEVICE</deviceNameType><ALARM>1</ALARM></rtc>
The alert() works with chrome but not IE.
How can I fix this problem in Internet Exploer 8?
If you're using jQuery at all (i know you said JS) try this:
$.ajaxSetup({
cache: false
});
AJAX get requests are cached in IE. You need to set cache to false: http://api.jquery.com/jQuery.ajax/
benhowdle89's solution affects the global ajax settings, so any ajax request on the page will not cache results.
精彩评论