Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client ajax updates from the server without repeating code every second?

Tags:

ajax

php

mysql

I would like to check a database for a change using ajax. However, I do not want to overload the server by constantly checking it every second.

Is there any other way of updating the clients from the server? Can jquery listen for event server side?

Thanks

like image 388
Skeep Avatar asked Oct 26 '22 21:10

Skeep


1 Answers

You could use long-polling. Basically you send a request to the server, and it waits to return with a response. The server will hold the connection until data is available, and it will then return the response containing the data.

For examples of long-polling with Javascript (frameworks), see this question. Additionally, PerplexedLabs did a short tutorial/example of long polling with jQuery and PHP earlier in 2009. You can view it online at http://blog.perplexedlabs...javascript-long-polling/.

like image 179
Sampson Avatar answered Nov 13 '22 05:11

Sampson