Answer the question
In order to leave comments, you need to log in
How to update content without reloading the page in Javascript?
Good afternoon, you need to update the data from the database (requests via php) without updating the pages, i.e. in real time.
Let's say a person had 100r on the balance sheet, I changed it to 200 in the database and his balance changed without rebooting.
An example please.
Answer the question
In order to leave comments, you need to log in
Your page has to learn from somewhere about the actual fact of the update and get this updated data.
There are three approaches:
1. periodically make an ajax request, asking "has nothing changed? And now? but right now?"
2. keep a long polling connection to the server, waiting until the server says "your new balance is 100500"
3. keep a websocket connection to the server, waiting again.
each has its own advantages and disadvantages.
The first one is hammering with requests, creating a load. The second two hold connections, which again are not free.
It is difficult to advise which of them to choose now, there is not enough information.
After we received new data, everything is simple there:
someElement.textContent = newBalance;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question