Skip to content Skip to sidebar Skip to footer

Refresh Php Variable Inside A Javascript Function

So I'm doing an operation inside the javascript to attribute a javascript variable to a php value that is obtained via txt file. But I want to repeatedly refresh. I've seen a few q

Solution 1:

The Problem

PHP is evaluated only when the request is made to the server, and once the server sends the response (sending the data of the .txt file), even if the contents of the file change, it cannot be retrieved (unless another request is made to the server)

Solution

In the setInterval function, make an ajax request to some page, and program that page to return the contents of the file. This way you can update the page in real-time as well as get the updated content after page load as well.

If you're new to AJAX, this might be helpful

Ajax tutorial for post and get

Post a Comment for "Refresh Php Variable Inside A Javascript Function"