简体   繁体   中英

“Real time” update with Ajax

I have the webpage that displays "questions" and "answers" for users. Questions are created by admin. I am using PHP.

New requirement has come to update questions/answers for users in "real time" (this is not so real time like in strategy game, but I will call this real time). When admin created new question, user should see it (new question appears). When admin closes existing question, then it disappears from user point of view.

I am thinking to create it using ajax and javascript timer- to call ajax each minute and to update results. I wonder is this is the right way?

And also I wonder about usability/performance... I really do not need to update those questions for user that were not changed... What are your suggestions to determine, which questions were changed by admin (maybe I should add something like "last_update_date" for question in database and put "last_update_date into hidden field for each question" and compare?

If you do not want to implement your own logic with Socket.io (as suggested in the comments), you should have a look at some of the services available online.

I've been using Pusher.com for some time and is quite happy about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM