-1

I'm a newbie to php. How can i refresh a div container on the page without reloading the whole page?

I don't want to have the flicker when the reload is done. It looks more elegant if the div container refreshes. In the div container I show a text changing at different times per day. I would really appreciate your help here.

Example of the div container:

<?php
    if (date('w') == 6) {
      if (date('H') >= 5 && date('H') < 7) { ?>
         <div style="position: fixed; top: 45px; width: 100%">
           <table style="background-color: #0307f6;" width="100%">
             <tr style="background-color: #0307f6;">
               <td align="center" style="color: #FFF;" width="100%">ACTUALLY : lorem ipsum </td>
             </tr>
           </table>
         </div>
<?php  
       }
    }    
?>
2

1 Answer 1

1

Like Eddie already said, use ajax. That means that your HTML will make a request (ask for information) to your PHP code. Your PHP code will then "reply" with the requested information and your HTML code can then use that to render the page.

With AJAX, all that happens in the background and the user will not see anything, meaning no flickering.

This was a SUPER simple explanation to get you introduced to the idea.

Check here for a basic intro: https://www.w3schools.com/xml/ajax_intro.asp

Also, someone else already asked a similar question. Try to check that before asking the same thing again ;)

Check this post: Change DIV content using ajax, php and jQuery

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.