0

I know similar questions are raised many times, as I can see in the search. But I could not manage the refresh work in PHP for the list I'm using.

Refreshing the datetime was an easy test, which works. When switching to complex function, it doesnt. And this is confusing me. Hope you can tell me what I'm doing wrong.

Currently I'm preparing a page which loads X amount of locations and its reservations. Each second I want the locations and their total counts being refreshed.

Currently my code:

DIV, containing a PHP functions that launches a MySQL query, lists the data to HTML format/layout:

echo '  <div id="location">
            <div id="session">
            '.listLocationToBook($current_user_id, $filter_city, $date, $token, $url).'
            </div>
        </div>';

Script

<script type="text/javascript">
    setInterval("my_function();",3000); 
    function my_function(){
      $('#location').load(location.href + ' #session');
    }
</script>

When I put a timer (datetime) in stead of the PHP functions in the div, I see the time increasing with the 3 secs.

Any reason this is not working with the PHP function? How can I solve/work towards an alternative?

Thanks in advance

2
  • I guess this is obvious but, is the function returning anything? Maybe adding a snippet of the function to your question would help. Also have you tried debugging by echoing the function outside of all that to see if it is working at all?
    – cyw
    Commented Jun 14, 2020 at 7:37
  • @dune184, thanks for your repply, the function is working and has an output without adding it into javascript. I found the solution in the following: the function did the echo on the html snippet. Instead of eacho I put this into an a variable and returned this variable. Without the return, the content was not showing in Javascript. Another thing I learned, maybe useful for someone else. Commented Jun 14, 2020 at 13:20

1 Answer 1

0

the function is working and has an output without adding it into javascript. I found the solution in the following: the php function did the echo on the html snippet. Instead of echo I put this into an a variable and returned this variable. Without the return, the content was not showing in Javascript. Another thing I learned, maybe useful for someone else

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.