JQuery Ajax update not working in IE

I have a <ul> which is updated every ten seconds to check if there are any new tweets (pull from twitter). This works fine in Firefox and Chrome, etc., but it doesn’t 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 goes wrong? Thanks

+4
source share
3 answers

I managed to fix it, it turned out that this is a cache problem with IE. Therefore, to fix this, I put a unique request containing unix time at the end of the PHP file call. For instance:

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

Perfect!

+4
source

the .load () documentation points to loading page fragments:

Note that the extracted document cannot be a complete HTML document; that is, it cannot include (for example) <html> , <title> or <head> elements. jQuery uses the innerHTML browser property for the element to parse the document, and most browsers do not allow this way to parse elements without a body.

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

+1
source

I know that the question is already answered, but if someone reads this question today or later, I think the problem is in the cache, IE will have the page answer in the cache, so it will not ask again about it.

Add the following line on the server side to prevent it.

 header('Cache-Control: no-cache'); 
+1
source

Source: https://habr.com/ru/post/1308221/


All Articles