1

i am at this moment stuck with a problem :

Let's say there is two computers : A, and B.

We do "post request" and "insert in mysql database" with computer A.

I want to refresh a page on computer B (or better, a div with Ajax), when my tables in my database are updated.

The easiest but worst solution that i found is to do a select in the database with a counter, every X seconds for exemple and refresh the page of B if the counter is higher than X secondes before.

I'm working on this project in php, javascript, and jQuery.

How can i do that ? I want a good solution, but quickly realisable.

Thanks !

(Computer A and Computer B aren't in the same page)

  • Computer A and B are on the same page, then when Computer A Insert data. You want the computer B to see the data inserted without reloading the page? Am i right? – Genina Anne Gabuten Apr 25 '17 at 12:48
  • XMLHttpRequest is ajax - it makes one asynchronous HTTP request. Websockets keep an open connection and messages can be sent in both directions. They aren't the same thing and so one is not better than the other, it's comparing apples to oranges. – Bill Apr 25 '17 at 14:13
  • Genina, no they are in two different pages – Oktay Seeven Apr 25 '17 at 16:12

1 Answers1

0

You should have your clients keep a socket connection open with the server. socket connections stay open and you can send messages back and forth. When the table is updated on the server, broadcast a message out and then have the client side listen for that message, and refresh the table.

Some good links on sockets in this answer: https://stackoverflow.com/a/1736398/1879895

Community
  • 1
  • 1
Bill
  • 3,478
  • 23
  • 42