Вопрос

My problem is simple yet I couldn't find the best solution to it.

I want to know if someone voted on a post ON PAGE LOAD (not when they vote) and if they did, change the voting image so that they can see they already voted on it.

Best solution that came to my mind was to save cookies, first question is "is it good practice to save cookies and loop through all posts to find if cookie exists?"

second question is: if it is a good solution, what should be the way to save cookies? Since only registered members will be able to vote, keeping username and postId should be enough.. or not?

Thank you

Это было полезно?

Решение

Depending on the browser, cookies have a size limit so this may not be the best approach.

You mention that you are keeping the votes in the DB. When the page is requested just look at that table and send the appropriate image down.

Другие советы

Since you are keeping the votes in a database, the best approach would be to determine if the vote occurred on the server-side and create the page accordingly.

Javascript can be used on the client side to asynchronously update the database and the GUI when a vote is cast (much like what stackoverflow does when we vote here).

Best way is to use Ajax/ JQuery to update your images. Use WebMethods

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top