views:

33

answers:

2

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
I'm completely horrible with javascript and jquery, How do I get the content from a PHP file?
Kraffs
+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
That worked, thanks all
Kraffs