0

As of right now, I have a PHP page that automatically refreshes every 8 seconds. When it refreshes, it updates information on the page that it gets from an API. How do I refresh the PHP script [clear the current data/html text, echo the new data] without refreshing the page? Thanks in advance!

3
  • use ajax.. you cannot do it with just hp, you need client side javascript language. api.jquery.com/jquery.ajax Commented Dec 20, 2015 at 4:42
  • I'm not sure how... Can you give me a quick example as to how this would be done? Commented Dec 20, 2015 at 4:43
  • You need to learn to use AJAX with javascript or jQuery. Commented Dec 20, 2015 at 4:43

2 Answers 2

1

create a page that contains ajax code, (javascript or jquery). Here its jquery ajax(its simple)
create another php page and put all required php code there.
So we have page 1 with ajax and page 2 with php code

in page 1

$.ajax({ method: "POST", url: "yourphppage.php", //php page link here data: { name: "John"} // send any data to php page if needed }) .done(function( msg ) { //msg contains the response from php page... alert( "Data Saved: " + msg ); //use msg to update the page without refresh }); 

now in page 2 add the php code you have... this page 2 will return response to page 1. This is how ajax works and the result is a page that updates without full refresh

Sign up to request clarification or add additional context in comments.

1 Comment

I see. Where would I put the code to run this script every 8 seconds?
0

You cannot do it with PHP, you need to make an ajax request by javascript.

An example of how to do it:

http://www.w3schools.com/ajax/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.