Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 757731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:23:51+00:00 2026-05-14T15:23:51+00:00

Say I have a website which shows the user ten images and asks them

  • 0

Say I have a website which shows the user ten images and asks them to categorise each image by clicking on buttons. A button for “funny”, a button for “scary”, a button for “pretty” and so on. These buttons aren’t exclusive. A picture can be both funny and scary.

The user clicks the “funny” button. An AJAX request is sent off to the database to mark that image as funny. The “funny” button lights up, by assigning a class in the DOM to mark it as “on”.

But the user made a mistake. They meant to hit the next button over. They should click “funny” again to turn it off, right?

At this point I’m not sure whats the most efficient way to proceed.

The database knows that the “funny” flag is set, but it’s inefficient to query the database every time a button is clicked to say, is this flag set or not, then go on with a second database call to toggle it.

Should I infer the state of the database flag from the DOM, i.e. if that button has the class “on” then the flag must be set, and branch at that point?

Or would it be better to have a data structure in Javascript in the page which duplicates the state of each image in the database, so that every time I set the database flag to true, I also set the value in the Javascript data to true and so on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:23:52+00:00Added an answer on May 14, 2026 at 3:23 pm

    I would keep the state of the element in the js on the page and just issue state-change requests via Ajax. On the server side it is reasonable to either process directly or introduce a state validation check.

    This depends on various aspects of your system architecture, however. If the rating is shared between users or other similar scenarios you may need to enforce the round-trip to check what the current status is (or if you have additive nominal flags)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a website and a database of that website hosted locally on
Say you have a website for users to search for hotel rooms for rent.
Say I have a file in my kohana 3 website called assets/somefile.jpg . I
I have a website I want to regexp on, say http://www.ru.wikipedia.org/wiki/perl . The site
Let's say I have a flash video streaming website, what are some ways in
So lets say I have the following scenario. http://website.com:8080 and http://website.com:8080/demo Is there any
Let's say I have N > 1 TCP-based, connection-oriented (read: not a website) services
I have 1 blog say xyz.blogspot.com ,now am uploading my own website,so I want
I have a headline on a website I'm programming; let's say the headline says
I have access to a public folder of my website. which has number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.