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.

2 Answers 2

3

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 
Sign up to request clarification or add additional context in comments.

Comments

0

Sure you can. Use setInterval to execute something every x milliseconds.

setInterval(function(){ // your code }, 5000); // 5 seconds 

1 Comment

I'm completely horrible with javascript and jquery, How do I get the content from a PHP file?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.