Is this possible? I need to get some data from another phpfile and I want it to appear every X seconds without you having to refresh the page.
A:
Sure you can. Use setInterval
to execute something every x milliseconds.
setInterval(function(){
// your code
}, 5000); // 5 seconds
Luca Matteis
2010-09-07 18:01:13
I'm completely horrible with javascript and jquery, How do I get the content from a PHP file?
Kraffs
2010-09-07 18:02:49
+2
A:
Yes, that is known as "polling" or "periodic refresh"
You can use setInterval
(see @Luca's answer) and jQuery's ajax API to communicate with the PHP file, and jQuery's DOM manipulation API to change the contents of the page. In its simplest form:
setInterval(function(){
$.get('ajax.php', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
}, 5000); // 5 seconds
NullUserException
2010-09-07 18:03:47