views:

67

answers:

3

http://www.gomatagorda.com/matagorda-weather/

I'm using jQuery to load [root]/data/weather-full.htm which is uploaded by the weather station every 60 seconds.

I'm loading that file every 30 seconds, to maximize freshness of the data.

In Internet Explorer 7/8, after a refresh, half of the right column of data disappears. I've tried various solutions including DIVs, empty DIVs before and after, and even tables. On every refresh, the first part of the textual data disappears.

Any help with this is appreciated. I've been debugging this specific error for about 2 months.

Thanks!

A: 

If i had to guess i would say youre catching the file while its being written to. Without going into the detail of coding up a file locking system to protect reads while its being written to i would suggest testing the file for the expected last line of data... if its not there then defer the load for another few seconds/milliseconds.

prodigitalson
You would expect to see the missing data occur in other browsers if this was the case. The initial load also always seems to work in IE.
Jonathon
+2  A: 

If you use $.get, or $.ajax with GET method, then IE will cache the AJAX request. To prevent it, this simple hack will do it:

$.get(URL,
      { nbRandom: Math.random() },
      function(data){
        //process AJAX response
      });

nbRandom is a parameter name that not used by the URL, but just to make IE think that this is the new request, so the cache will not be used.

UPDATE

I have examine the site. Please bear in mind that I don't use IE. In the page, I see there are single <div> tag after <div id="weatherdata"> close tag. This single <div> don't have close tag, but immediately followed by </td>. Please examine the tag balance in the page, make sure all balanced and valid XHTML. Most bug and quirk behavior is come from unbalanced and unclosed tags.

Other thing that might or might not related, I never use .load() in my codes, and I never get any weird or bug in the IE. Below I rewrite your functions:

function UpdateWeatherBar(){
  var d = new Date();
  $.get("http://www.gomatagorda.com/data/weather.htm",
        { t: d.getTime() },
        function(data){
          jQuery("#weatherbar").html(data);
        });
}

jQuery(document).ready(function($) {
  UpdateWeatherBar();
});

var reloadcam = setInterval(function(){
  UpdateWeatherBar();
}, 30000);

You don't need to do if (document.getElementById("weatherbar") != null), jQuery do this for you automatically.

Using code above, you just need to write the AJAX in one place, then used it in any place. No duplicate code that will making hard when you need to update it. Also, since you call UpdateWeatherBar() using setInterval, moving jQuery(document).ready() block out from the function might make the bug gone.

I hope this and tag balanced checking will resolve the bug in IE.

Donny Kurnia
He's already adding time to the URL (unless he just changed it since your comment).
Jonathon
+1, and `(new Date()).getTime())` as the random would be a more sure way (just nitpicking i know..)
Gaby
yep, I added the time to prevent caching. and no I haven't changed anything on the site today. @Gaby: when watching the NET window in Firebug, the random result seems to always be different.
MesmerLab
A: 

The only thing strange I see is an extraneous </ right after the first THW Index that appears. Maybe this is messing up IE when it's added to the document tree? Fix the HTML at that point and see if you get better results.

Jonathon
Wow, I didn't even catch that. But when IE does refresh the div, it only displays the data AFTER that part. I bet that's the issue.One small hurdle: I have to get with the client to upload a proprietary template .htx file. The weather station takes that file and replaces specific variables with the live data.Thanks! I'll report back after that little bug is fixed.
MesmerLab
I think it will fix it given the proximity of the extra `</` to the start of the good data that appears. I did a bunch of stepping through the code and everything seems good besides that. As an aside, you may want to move the `jQuery(document).ready` outside of the function that gets called in an interval. It doesn't need to be called more than once.
Jonathon