CyberShot Posted October 15, 2009 Share Posted October 15, 2009 I have small script to generate a random quote when the page loads. It works. I decided to use javascript to refresh the div the code sits in every 10 seconds so that every quote would display if you were on the page for a while. My problem is that when the page loads, the div the quote sits in is empty and then after the given time, one quote will show up but it does not change. Here is my code <?php class quotes { function quotes() { switch(intval(rand(1,5))) { case 1: $this->quote = "A computer once beat me at chess, but it was no match for me at kick boxing -Emo Philips" ; break; case 2: $this->quote = "It was when I found out I could make mistakes that I knew I was on to something -Ornette Coleman" ; break; case 3: $this->quote = "You can't build a reputation on what you're going to do -Henry Ford"; break; case 4: $this->quote = "People are just as happy as they make up their minds to be -Abraham Linkcoln"; break; case 5: $this->quote = "Good advice is something a man gives when he is too old to set a bad example -Francois de La Rochefoucauld "; break; } } } $quotes = new quotes(); echo $quotes->quote; ?> and the jquery to run it function randomQuote(){ $('#rand').load('includes/quotes.php'); } $(document).ready(function(){ setInterval("randomQuote()", 1000); }); Quote Link to comment Share on other sites More sharing options...
CyberShot Posted October 15, 2009 Author Share Posted October 15, 2009 for some reason it started working on it's own 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.