0

On this problem some more people have stumbled and for non-ajax scenario there is already a solution : How to prevent multiple inserts when submitting a form in PHP?

(answered Jan 25 '10 at 17:02)

I'd like to know how could be implemented efficiently on both the server and client side a similar solution for the following problem :

  • there is a wall listing containing multiple items on which the users can click an ajax-enabled "i like" button (no page reload)
  • the user can have multiple browser windows opened on which can click "i like" buttons

Expected : Only the first click on the "I like" button for any of the wall items is taken at the server side into account and the following requests for the wall item are not handled anymore.

Community
  • 1
  • 1
marius_neo
  • 1,535
  • 1
  • 13
  • 28

2 Answers2

0

Keep track of the liked items of each user on the serverside (for example an extra database table). When a new like is going to be inserted, check if there is already an existing record in this table. If there is, the user has already liked this item and you dont't have to count it anymore.

Alex
  • 12,205
  • 7
  • 42
  • 52
  • When the requests are submitted on the same time, and for a given item there isn't "saved" state in the database, there will be done 2 times the save for the "i like" operation. – marius_neo Sep 30 '11 at 11:54
0

I think the best way is to use a session variable that store the current state, ie when someone clicks you "i like", on the server side, you check the state of the SESSION var.

Mika Andrianarijaona
  • 1,619
  • 17
  • 29
  • When the requests are submitted on the same time, and for a given item there isn't "saved" state in the session, there will be done 2 times the save for the "i like" operation. – marius_neo Sep 30 '11 at 11:52