Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    51
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Update Now Or Later? (Design Question)

    Hello, I have a question on design. I am working with an AJAX query that performs a simple, straight forward table update on clicking a button. The value toggles based on the click (If it is 1 it will change it to 0 and vice verse). The thing is that you can spam click this button and make it do a bunch of useless updates, when only the last value really matters.

    I was wondering if it would be a good idea to somehow store what you click somewhere, then update the table maybe every minute with just the latest choice per user. Is the effort in this even worth it or will MySQL keep up without problems? Thanks

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Only registered members should click, and since you are doing ajax you can emideately signal back with some graphical representation that value has changed.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    51
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BubikolRamios View Post
    Only registered members should click, and since you are doing ajax you can emideately signal back with some graphical representation that value has changed.

    Yes that's what I am doing. It's just that the user can spam click the button. I was thinking of putting a timer so you may only click it once every 2 seconds or so, but that would make it feel sluggish if you accidentally miss toggled it and want to click fast to get it back.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    I don't see anything wrong with "buffering" the clicks in the JS code.

    You'd use a setTimeout that will trigger the AJAX hit after, say, 15 seconds? If the user toggles again within that time, you clear the first timeout and set another one. Etc.

    If the user leaves the page before the timeout expires, you clear the timeout and do the AJAX as part of the <body onunload="..."> processing.

    Pretty simple coding, really.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    51
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    I don't see anything wrong with "buffering" the clicks in the JS code.

    You'd use a setTimeout that will trigger the AJAX hit after, say, 15 seconds? If the user toggles again within that time, you clear the first timeout and set another one. Etc.

    If the user leaves the page before the timeout expires, you clear the timeout and do the AJAX as part of the <body onunload="..."> processing.

    Pretty simple coding, really.
    Sounds good to me, I agree it's straight forward, I just wasn't sure if I should even bother with it or not. Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •