div stops being updated in IE11

4

In a project I'm developing, I need to update some fields on the page every 50ms (this is adjustable). The problem is that when I test in IE, the fields are no longer updated from time to time, with no explanation whatsoever. Usually it works for a few seconds and stops.

I have already verified the following: the (IE) debugger does not acknowledge anything, it works smoothly in Chrome and Firefox, and (xmlhttp.readyState == 4 && xmlhttp.status == 200) conditions are satisfied, setInterval() is working. The page only resumes on the F5 basis.

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();
}

Apparently it's like div's has failed, but that's not happening (I can access manually, and it works in other browsers).

    
asked by anonymous 17.02.2014 / 00:07

2 answers

4

The problem is that Internet Explorer is verifying that requests are repeated and, as such, it goes to the cache.

Apparently, it does not do this the first few times, so it takes time to start crashing.

To resolve this, you must prevent IE from using the cache for this request. The solution for jQuery (% with% with% with%) is to use an additional unused GET parameter.

  

It works by appending "_ = {timestamp}" to the   GET parameters.

Translating:

  

It works by adding "_ = {date-time}" at the end of the GET parameters.

Varying the GET parameters (whether random numbers or sequential numbers) is one way to avoid this problem.

There are other ways to do this, for example by controlling HTTP requests. The server can send to the client (in request $.ajax ):

Cache-Control: no-cache
    
17.02.2014 / 03:12
4

I was able to solve the problem. As discussed in the question comments, the cause of the problem was that IE stopped requesting information from the server and started using the cached information. As a result, it looked as if the results were no longer up to date.

As the page I am developing does not need to cache information, I solved the problem by adding some HTTP parameters in the requests, as I found in summer in English OS and here :

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

Being first for HTTP 1.1, and second for older browsers. These three parameters are necessary because some more anarchist browsers do not respect some parameters.

    
17.02.2014 / 03:16