woolyg Posted March 18, 2011 Share Posted March 18, 2011 This could possibly be grouped with this post: http://www.phpfreaks.com/forums/index.php?topic=327454.0 - the code works in FF and Chrome, etc, but not IE, and I'm wondering if anyone has seen a workaround. Basically, the page is loading a setInterval() on the fly to dynamically update a user's credit left in their account, and show it within a constantly updating div. Every 10 seconds, it runs an ajax call to a PHP script, and the info comes through. It works with everything but IE. I know IE deals with ajax differently that the other browsers, etc, but does it have a distinct problem with setInterval()? Here's the code being used: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Updater test</title> <script language="JavaScript" type="text/javascript"> function ajax_refresh(dataSource, divID) { var XMLHttpRequestObject = false; if (window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); } else if (window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp"); } if(XMLHttpRequestObject) { var obj = document.getElementById(divID); //var starting_data = obj.innerHTML; document.getElementById(divID).innerHTML = obj.innerHTML; XMLHttpRequestObject.open("GET", dataSource, true); XMLHttpRequestObject.onreadystatechange = function() { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { obj.innerHTML = XMLHttpRequestObject.responseText; delete XMLHttpRequestObject; XMLHttpRequestObject = null; } } XMLHttpRequestObject.send(null); } } // STANDARD AJAX CALL END </script> </head> <body> <script type="text/javascript"> var refresher_update_user_credit_left_div = 0; refresher_update_user_credit_left_div = setInterval("update_user_credit_left_div('<?php echo $user_id; ?>')", 10000); function update_user_credit_left_div($user_id){ // FUNCTION 48 ajax_refresh('<?php echo base_url(); ?>assets/ajax/ajax.update_user_credit_left_div.inc.php?uid=<?php echo $user_id; ?>', 'user_credit_left'); } // FUNCTION 48 </script> <div id="user_credit_left" title="Your account credit."></div> </body> </html> All input appreciated. Regards WoolyG Link to comment https://forums.phpfreaks.com/topic/231039-setinterval-calling-ajax-not-working-in-ie/ Share on other sites More sharing options...
woolyg Posted March 18, 2011 Author Share Posted March 18, 2011 OK, having delved a bit deeper, it was because IE was caching the ajax call. Once I changed: function update_user_credit_left_div($user_id){ // FUNCTION 48 ajax_refresh('<?php echo base_url(); ?>assets/ajax/ajax.update_user_credit_left_div.inc.php?uid=<?php echo $user_id; ?>', 'user_credit_left'); } // FUNCTION 48 to: function update_user_credit_left_div($user_id){ // FUNCTION 48 ajax_refresh('<?php echo base_url(); ?>assets/ajax/ajax.update_user_credit_left_div.inc.php?uid=<?php echo $user_id; ?>&t=' + (new Date()).getTime(), 'user_credit_left'); } // FUNCTION 48 .. the div began updating every 10 seconds as expected! Solved. Hopefully this can help someone else out some time. WoolyG Link to comment https://forums.phpfreaks.com/topic/231039-setinterval-calling-ajax-not-working-in-ie/#findComment-1189322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.