P
P
Pavel Andreichenko2017-09-20 13:51:39
PHP
Pavel Andreichenko, 2017-09-20 13:51:39

How to display data dynamically on frontend (Vue.js) when data changes on backend (PHP)?

For example, there is an admin panel whose frontend is written in Vue.js (vuex is responsible for the state), and the backend is in PHP.
By clicking on the button, Frontend makes a request to the backend via Ajax and receives a response in json format, a selection from the database, for example, a list of users. When you press the button, everything works, the data received is relevant, the question is:
Which way to dig to dynamically update the list of users without pressing the button, a user appeared - the admin automatically saw the updated list?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Anton, 2017-09-20
@MB116

If you do not use websockets, then the easiest way is to store the date of the last update of the list and request it from the front once every few seconds. If it is greater than the one that was during the previous data request, then request the list again.
Well, if we have the opportunity to use web sockets, then it’s easier (and at the same time more difficult). In the simplest case, the application that inserts data and serves websockets is one and the same. Then just send a notification to all fronts on the sockets and they request an updated list. Or the helmet immediately changes and the fronts change their data. When the application is divided into parts, a complication is obtained: when the data changes, the helmet sends a signal from the part that changes the data to the part that serves websockets and it notifies the fronts. Well, or we integrate any system of management of queues of messages like RabbitMQ. In general, the scope for imagination begins.

D
Dmitry Luzanov, 2017-09-20
@dmitry_luzanov

websockets

S
shelomanovd, 2017-09-21
@shelomanovd

long pooling. You podrubaeshsya to the server you hang up the answer. Changed the data returned to the client and subscribed again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question