div stops being updated in IE11

Asked

Viewed 159 times

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

  • @Emersonrochaluiz Thanks for the suggestion, but I tested here with bigger delays and the problem remained.

  • 1

    The IE dev tools network request panel shows what? Requests may be being made, the result coming from the cache, and visually nothing changes.

  • The adc_array is not declared with var therefore it is a global variable. Other functions may be interfering with this variable.

  • @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.

  • 1

    @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 I took the test of console.log and is as you said. Repeating (only in IE).

  • 1

    @Lucasnuns Try merging ignored GET parameters (./rtu:analogic_inputs?v=[int incrementado de cada vez]) and see if the problem still exists.

  • @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.

  • @luiscubal Your suggestion turns easy an answer, do not want to post?

  • @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 I will publish a reply but I never got confirmation that my version worked.

  • @bfavaretto Ok. I was hoping the luiscubal post, but I will post what I did too.

  • 1

    @luiscubal Passing an incremental number or a timestamp on the url is one of the traditional methods of avoiding ajax caching, it works yes.

Show 9 more comments

2 answers

4


The problem is that Internet Explorer is checking that requests are repeated and therefore uses the cache.

Apparently, he doesn’t do it the first few times, so it takes time to start failing.

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

It Works by appending "_={timestamp}" to the GET Parameters.

Translating:

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

Changing the GET parameters (be it 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 (on request ./rtu:analogic_inputs):

Cache-Control: no-cache

4

I managed to solve the problem. As discussed in the comments of the question, the cause of the problem was that EI stopped requesting server information and started using the cached information. As a result, it appeared that the results were no longer updated.

As the page I’m developing doesn’t need to cache information, I solved the problem by adding some HTTP parameters to the requests, as I found in summer in OS English and here:

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

Being the first for HTTP 1.1, and according to for ancient navigators. These three parameters are necessary because some more anarchist browsers do not respect some parameters.

  • 1

    The answer in English does not mention the third line, and the first line has only the no-cache... Another reply in English on the subject that may be useful: http://stackoverflow.com/a/1383359/32775

  • @luiscubal I forgot to quote the second source, where I got these differences. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.