Home > Article > Backend Development > How to Retrieve Ajax Data at 10-Second Intervals Using jQuery?
jQuery: Retrieve Ajax Data at 10-Second Intervals
When designing a feedback display that incorporates real-time data retrieval, it's important to implement a method that updates the displayed content periodically. This can be achieved using jQuery's powerful Ajax capabilities.
To set up a feedback div that showcases new entries every 10 seconds, you can utilize the following approach:
Here's an improved example based on your provided code:
<code class="javascript">function get_fb(){ var feedback = $.ajax({ type: "POST", url: "feedback.php", async: false }).responseText; $('div.feedback-box').html(feedback).delay(10000).queue(function() { setTimeout(function(){get_fb();}, 10000); }); }</code>
Note: This approach schedules the next retrieval after the previous one has been completed. You can adjust the timing as needed to optimize display performance.
The above is the detailed content of How to Retrieve Ajax Data at 10-Second Intervals Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!