0

I want to know how can I reflect the change on the HTML as soon as the data changes on the database.

I am aware that I could poll the php file with setInterval function to periodically check if database value changed. However I am interested to know if it could be done without the setInterval function?

Presently the app uses jquery library and PHP backend.

thanks for any help in advance.

Based on the comments below and more research Accessing socket.io server via Apache served pages Accessing socket.io server via Apache served pages

I understand I need to have a node package running on my server to work with socket.io or websocket.io. I cannot take the liberty of installing it since I am on a VPS.

Therefore, its best to use Simple long polling example with JavaScript and jQuery as a snippet to my situation

Community
  • 1
  • 1
Gaurav
  • 191
  • 18
  • 1
    This may help you, http://stackoverflow.com/questions/3583203/server-polling-with-javascript#comment3758669_3583240 – Rajaprabhu Aravindasamy Nov 23 '13 at 17:45
  • @RajaprabhuAravindasamy Doesn't AngularJS have an alternative for this? Are you familiar with it? – Gaurav Nov 23 '13 at 18:04
  • 1
    Have you tried websockets? http://en.wikipedia.org/wiki/WebSocket – Claudi Nov 23 '13 at 18:44
  • 1
    Only way to do this without polling is with websockets. – levi Nov 23 '13 at 18:54
  • @Claudix and levi, I was just toying with them.. Anyway, once I am done.. I will post my answer.. Cheers! – Gaurav Nov 23 '13 at 19:14
  • @Claudix I have a Apache server running which moreover is a VPS server. I assume, implementing a socket.io requires NodeJS to work as the server. Could you please correct me if that's wrong. In case there's a way to do it with an Apache server, could you suggest how I could build the app without modifying the server settings. Or do you suggest comet(long) polling is the best solution to my problem. – Gaurav Nov 23 '13 at 19:35
  • You could start from here: http://stackoverflow.com/questions/11334320/using-websocket-on-apache-server. I'm also experimenting with websockets but I haven't deployed any application yet. – Claudi Nov 24 '13 at 00:19

0 Answers0