I write in php. I use Ratchet with ZMQ to work with websockets. I am trying to update the list of orders in the admin panel in real time when the client has successfully made an order. Everything is almost implemented: there is a permanent connection between the browser and the server, the data is coming up perfectly, but there are a few misunderstandings at the very process of updating the list of orders. How is it implemented? Look here: let the admin enter the page, connect to the server, use a certain js script to subscribe to certain events and wait for data from the server. When ordering, the server receives the same data from the client (name, phone, and so on) and sends it to the admin. And how to use that data? The idea was simply to use jquery to insert this data into html code, namely, to create a new line with this data in the table with orders, but this is quite a hemorrhoid and, as for me, is not correct. Or right? Tell me please

  • And what's the problem then? Received data, added to DOM. Let it be jQuery, or AngularJS, or ReactJS. No different from working through AJAX. Only transport - korytoff
  • Well, in ajax, you can update the whole div, but, as I know, it is impossible to use sockets - Kolya Vantukh
  • And how is the one connected to the other? AJAX and sockets are just a transfer, after receiving the data you are free to do anything you want - korytoff

1 answer 1

And what is the difficulty? You have it all right. And data transfer can be done like this:

You send a customer’s order number via web sockets when placing an order and when receiving an order number from a customer, make an internal API request for receiving data on the order (for example: / orders / {orderId}) within the administration panel, and insert an order or output a popup window that a new order has been received.

Of course, you can send all the information on the order via a web socket, but in fact you do not always need all the information on the order for notification, and you can get all the required data by ID.