开发者

Update a list with AJAX, but first check if user is already in that list

开发者 https://www.devze.com 2023-02-26 11:04 出处:网络
Hello I work at a page that initially displays a list with registered users in a contest (an user can be registered multiple times, but every user registered is displayed just once), and this list is

Hello I work at a page that initially displays a list with registered users in a contest (an user can be registered multiple times, but every user registered is displayed just once), and this list is updated at a certain time period with AJAX, I would like to display just users that aren't already in that list. Which option would be the best to use for this?

  1. Sending the array with the users from the page to the server, and PHP would compare this array with new users and return just users that aren't already in that list (this mean开发者_JAVA技巧s that I will send to the server a array with about 10-200 users, at every 30 seconds)
  2. Comparing AJAX result with the list of users from the page, and displaying just users that aren't already in the javascript Array (this means that the comparation will be made with javascript)


It's probably good to do something like this:

  1. Javascript: Send time last modified to server - Whenever the last new user was added to the list, not the time of the last request. At first this time will be the current time.
  2. PHP: Return all users that have entered the contest since this time.
  3. Javascript: If there are results, detemine which users are unique (however you wish) and add them to the list, updating the time last modified for the next request.

I would think this would be the least amount of data transfer if that is what you are concerned about.

0

精彩评论

暂无评论...
验证码 换一张
取 消