c_pattle Posted November 27, 2010 Share Posted November 27, 2010 I have some JavaScript that sends an AJAX request to the following PHP script every 4 seconds. The idea behind this is that every 4 seconds a new, randomly generate piece of content is loaded. This works fine in Firefox and Chrome, however when I test it in IE it seems to just load the same piece of content over and over again. I'm pretty sure there is nothing wrong with the script so could this be something to do with IE caching the first piece of content returned? Thanks for any help. $random_number = 0; $random_number = rand(1,6); if ($random_number == 1 ) { echo("<a href=\"\"><h4>Aliquam erat volutpat. Vivamus feugiat tempor quam, faucibus elementum.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae ante at erat tempor facilisis. Quisque blandit faucibus suscipit. Proin suscipit est sed. </p></a>"); } if ($random_number == 2) { echo("<a href=\"\"><h4>Quisque ac lacus nibh, ac semper ante. Sed imperdiet.</h4><p>Vestibulum aliquam pellentesque lacus quis mollis. Proin quis lobortis libero. Ut nec tempor lectus. Pellentesque habitant morbi tristique senectus et netus id. </p></a>"); } if ($random_number == 3) { echo("<a href=\"\"><h4>Suspendisse vestibulum dui augue, nec viverra erat. Proin id.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu sollicitudin elit. Cras mauris mi, luctus non luctus quis, tristique vitae turpis turpis duis. </p></a>"); } if ($random_number == "4") { echo("<a href=\"\"><h4>Vestibulum gravida elit posuere arcu.</h4><p>Phasellus sit amet rutrum purus. Cras vulputate pretium quam eleifend viverra. Morbi convallis eros ac tellus suscipit nec euismod nibh semper. In quam posuere. </p></a>"); } if ($random_number == "5") { echo("<a href=\"\"><h4>Vestibulum ante ipsum primis in.</h4><p>Aliquam consectetur aliquet libero. Mauris malesuada tortor eu ipsum mollis sit amet blandit erat sollicitudin. Cras consequat dui ac elit semper pharetra amet. </p></a>"); } if ($random_number == "6") { echo("<a href=\"\"><h4>Nam ornare, nisl non interdum aliquam, erat urna consequat elit, vel.</h4><p>Nulla ut libero est, eu convallis urna. Nullam fringilla mollis ligula, id fringilla enim sagittis non. Nunc lectus nunc, condimentum eget imperdiet massa nunc.</p></a>"); } Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 27, 2010 Share Posted November 27, 2010 When you send the request try appending a random number or the current timestamp to the URL, avoiding the caching. Quote Link to comment Share on other sites More sharing options...
c_pattle Posted November 28, 2010 Author Share Posted November 28, 2010 Thank you. Although I am having some trouble with my timestamp. When I try to print out the time stamp to the screen it just says "undefined". Am I doing anything wrong? var rand; // Setting the interval so that the function executes every 4 seconds setInterval(function(contentFeed) { rand = contentFeed.timeStamp; alert(rand); $.ajax({ type: "GET", url: "feed.php", success: function(data) { alert("success"); } }); }, 4000); Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 28, 2010 Share Posted November 28, 2010 Use the JavaScript date object. var date = new Date(); rand = date.getTime(); See how you go with something along those lines. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.