4
In a project I am developing I need to update some page fields each 50ms
(this is adjustable). The problem is that when I test in IE, the fields are no longer updated overnight, with no explanation whatsoever. Usually it works a few seconds and stops.
I’ve already checked the following: the (IE) debugger does not show anything, works smoothly on Chrome and Firefox, and conditions (xmlhttp.readyState == 4 && xmlhttp.status == 200)
are satisfied, setInterval()
is working. The page only works again at the base of F5.
The code I use to update the fields is as follows:
var adc_array = [0, 0, 0, 0, 0, 0, 0];
function update_adc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
adc_array = xmlhttp.responseText.split(" ");
for (var i = 0; i < adc_array.length; i++)
{
if(adc_array[i])
{
document.getElementById("adc" + i).innerHTML = adc_array[i] + " V";
}
}
}
}
xmlhttp.open("GET", "./rtu:analogic_inputs", true);
xmlhttp.send();
}
Where: the div's
updates are adc0, adc1 ,adc2, adc3, adc4, adc5 and ./rtu:analogic_inputs
is the address that picks up the information that will be updated (and is working properly in IE).
Apparently it’s like the xmlhttp.open()
had failed, but this is not happening (I can access manually, and works on other browsers).
This is possibly because the delay is small, especially if the application loses focus. In Gecko and Webkit, for example, I think if using setInterval and application is not in focus it performs the routines at no less than 100ms or 1000ms. Maybe you’re reaching a similar limit
– Emerson Rocha
@Emersonrochaluiz Thanks for the suggestion, but I tested here with bigger delays and the problem remained.
– Lucas Lima
The IE dev tools network request panel shows what? Requests may be being made, the result coming from the cache, and visually nothing changes.
– bfavaretto
The
adc_array
is not declared withvar
therefore it is a global variable. Other functions may be interfering with this variable.– luiscubal
@luiscubal Sorry, I forgot to put in the post. I will edit there. But I think the problem lies more to what the bfavaretto said. But I still can’t figure it out.
– Lucas Lima
@Lucasnunes To test this hypothesis, I propose the following test: put a console.log inside the
onreadystatechanged
. If the result comes from the cache, then console.log will appear, but repeated.– luiscubal
@luiscubal I took the test of
console.log
and is as you said. Repeating (only in IE).– Lucas Lima
@Lucasnuns Try merging ignored GET parameters (
./rtu:analogic_inputs?v=[int incrementado de cada vez]
) and see if the problem still exists.– luiscubal
@luiscubal I managed to solve the problem! It was the same cache. I added some HTTP parameters (in my case there is no need to store cache even) and solved. Use the following: http://stackoverflow.com/questions/1093112/is-there-a-way-to-make-internet-explorer-not-cache--particular-website.
– Lucas Lima
@luiscubal Your suggestion turns easy an answer, do not want to post?
– bfavaretto
@Lucasnunes The solution you used could also be posted as a response, with a brief explanation. If you and luiscubal post answers, other users with the same problem will be able to easily find two solutions :)
– bfavaretto
@bfavaretto I will publish a reply but I never got confirmation that my version worked.
– luiscubal
@bfavaretto Ok. I was hoping the luiscubal post, but I will post what I did too.
– Lucas Lima
@luiscubal Passing an incremental number or a timestamp on the url is one of the traditional methods of avoiding ajax caching, it works yes.
– bfavaretto