I am experimenting on jQuery and PHP now. And Im having this problem. So I have this code
$(document).ready(function(){
$('.bopa').load('accounts.php');
});
It works perfectly fine. But the thing is I want the content of the div to refresh every 30 seconds. So that when someone submits something in the database, it will immediately apeear after 20 seconds. Is that possible?
This code will execute the load every 30 seconds.
$(document).ready(function(){
setInterval(function(){
$('.bopa').load('accounts.php');
},30000);
});
The number 30000 is in milliseconds.
1000 milliseconds = 1 second
If you want some more control, for example the ability to disable the refreshes, you can do something like this -
var refreshInterval = '';
$(document).ready(function(){
refreshInterval = setInterval(function(){
$('.bopa').load('accounts.php');
},30000);
});
Then anytime you want to cancel the refresh every 30 seconds you can call -
clearInterval(refreshInterval);
References - window.setInterval (Mozilla Developer Network)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With