tags:

views:

60

answers:

2

Hi, I have a <ul> which refreshes every ten seconds to check if there have been any new tweets (its pulling from a twitter feed). This works fine in Firefox and Chrome etc, but it does not work in any version if Internet Explorer.

My code is as follows:

setInterval(function() {
    $("#banter .scroll-pane").load(location.href+" #banter .scroll-pane>*","");
}, 10000);

My PHP function creating the list is as follows:

function showTweets($section, $limit, $class) {
    $result = mysql_query("SELECT * FROM hash WHERE section = '".$section."' ORDER BY date DESC LIMIT ".$limit);

    echo '<ul class="scroll-pane '.$class.'">';
        while($row = mysql_fetch_array($result)) {
            echo '<li>';
                echo '<p>'.html_entity_decode($row['tweet']).'</p>';
                echo '<a href="'.$row['user_url'].'">'.$row['user'].'</a>';
            echo '</li>';
        }
    echo '</ul>';
}

Any idea what's going wrong? Thanks

+1  A: 

The documentation of .load() states this about loading page fragments:

Note that the document retrieved cannot be a full HTML document; that is, it cannot include (for example) <html>, <title>, or <head> elements. jQuery uses the browser's innerHTML property on a element to parse the document, and most browsers will not allow non-body elements to be parsed in this way.

This is probably the problem here - since you're loading location.href, I assume you're getting back a full HTML document. Creating a PHP page that retrieves only the relevant part of the HTML should fix this.

interjay
Hi, I tried this, I put my function in a PHP file and called that instead, and it still doesn't update in IE.
Probocop
+1  A: 

I managed to fix it, turns out it was a caching issue with IE. So to fix it I put a unique query containing the unix time on the end of the call to the PHP file. For example:

setInterval(function() {
    $("#banter .scroll-pane").load('test.php'+"?ms=" + new Date().getTime());
}, 6000);

Perfect!

Probocop