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

  • SEARCH
  • Home
  • 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 7498503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:29:58+00:00 2026-05-29T19:29:58+00:00

I always used something like this: $(a.button).click(function() { data = …; url = …;

  • 0

I always used something like this:

$("a.button").click(function() {
    data = ...;
    url = ...;
    $.post(url, data, function() {
        $(this).toggleClass('active');
    });
});

The problem is when an user has a slow connection and clicks on that button, it doesn’t seems to do anything, because the button will change the own status (adding the active class) once the request is complete. Of course I can “fix” this behavior by adding a spinner while the request is loading.

Now check out this one:

$("a.button").click(function() {
    $(this).toggleClass('active');
    data = ...;
    url = ...;
    $.post(url, data, function() {
        // if request is successful do nothing
        // else, if there's an error: $(this).toggleClass('active)
    });
});

In other words, I change the button status instantly when the button is pressed and after this, I check for success/error. Is this a good way? What you think about? Are there other ways?

  • 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-29T19:29:59+00:00Added an answer on May 29, 2026 at 7:29 pm

    This is more of a UI question than code. Personally I prefer to show the spinner in cases where it could be confusing if there is no response. Since I don’t know what class you’re toggling and what effect it has on the element, I wouldn’t know if toggling before success would be confusing at all.

    One way or another, everyone alive knows the loading spinner. It’s probably safe to go with that.

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

Sidebar

Related Questions

Is this ok? NSDate *myDate; Because I used something like this before: NSDate *myDate
Some background; I'm quite used to PHP, and I always used something like 'connect.ini'
I have a constexpr function that looks something like this: constexpr int foo(int bar)
I had always used something similar to the following to achieve it: INSERT INTO
I started with CSS so I always used brackets this way: #content { selector:
So I have a function that looks like this: @SuppressWarnings(unchecked) public static <E> Set<E>
when programming in Java I practically always, just out of habit, write something like
So, I'm trying to consume a webservice using something like this: $client = new
Currently I do something like this: class Foo { // Declare Fields [FieldName("F_BAR")] public
I always used a normal PHP file and just defined the variables in that

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.