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 1091477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:32:01+00:00 2026-05-16T23:32:01+00:00

I have a button that performs an ajax post — I want to disable

  • 0

I have a button that performs an ajax post — I want to disable the button, then perform my work, then upon completion — I want to re-enable the button. My interaction includes swapping out the image button (to a grayed out image button), and presenting a spinner. When complete, I hide the spinner and restore the original button image.

My approach includes unbinding, then rebinding the click event.

Here’s my code — it works great — but, I want to know if this is a proper/efficient/acceptable strategy?

// Update club name
$j('#btnUpdateClubName').bind('click', updateClubName);

function updateClubName() {
    var $this = $j(this);
    var $spinner = $this.next('.spinner');
    var renderURL = RES.BuildClubUpdateURL("UpdateClubName");

    $this.ajaxStart(function() {
        $this.attr("src", imgPathSaveAndUpdateBtnDisabled).unbind('click').addClass('wait-cursor');
        $spinner.show();
    });

    $j.ajax({ type: "POST", data: $j('#hidStandingOrderId, #txtClubName, #clubOrderIdEditClubName').serialize(), url: renderURL, dataType: 'html', contentType: 'application/x-www-form-urlencoded',
        success: function(data) {
            // do some stuff
            }
        }
    });

    $this.ajaxComplete(function() {
        $spinner.hide();
        $this.attr("src", imgPathSaveAndUpdateBtn).bind('click', updateClubName).removeClass('wait-cursor');
        $j("#cbEditClubName").colorbox.close();
    });
}
  • 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-16T23:32:02+00:00Added an answer on May 16, 2026 at 11:32 pm

    What you have works but it is a bit wasteful, as it adds a new ajaxStart and ajaxComplete handler each time the function runs, I would make one suggestion though, change your .unbind() call to be more specific since you have the information. If you change this:

    .unbind('click')
    

    To this:

    .unbind('click', updateClubName)
    

    You can have other click events without the .unbind() interfering, it’ll only unbind that one handler.


    An overall better alternative (to me, you can debate whether it’s “better”) without rebinding would be to store a variable to know you’re currently posting using $.data() and .data(), for example:

    $j('#btnUpdateClubName').bind('click', updateClubName);
    
    function updateClubName() {
        if($.data(this, "posting")) return false;   //are we posting? abort!
        $.data(this, "posting", true);              //set variable
        var $this = $j(this);
        var $spinner = $this.next('.spinner');
        var renderURL = RES.BuildClubUpdateURL("UpdateClubName");
    
        $this.attr("src", imgPathSaveAndUpdateBtnDisabled).addClass('wait-cursor');
        $spinner.show();
    
        $j.ajax({ type: "POST", data: $j('#hidStandingOrderId, #txtClubName, #clubOrderIdEditClubName').serialize(), url: renderURL, dataType: 'html', contentType: 'application/x-www-form-urlencoded',
            success: function(data) {
                // do some stuff
                $spinner.hide();
                $this.attr("src", imgPathSaveAndUpdateBtn).removeClass('wait-cursor')
                     .data("posting", false);   //clear it out, ready to post again
                $j("#cbEditClubName").colorbox.close();
            }
        });
    }
    

    With this approach if you’re doing a POST the data for “posting” is true, and future clicks just abandon out…not until the response comes back and your success code runs is the button re-enabled. It’s the same effect but no duplicate handlers and no re/un-binding.

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

Sidebar

Related Questions

I have a button that I would like to disable when the form submits
I have a Login button that I want to be disabled until 3 text
I have a form on an HTML page with multiple submit buttons that perform
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have a Button that is looking at 2 comboboxes to make sure they
I have a submit button that is a block of HTML code because of
I have a form in C# that has a button that, when clicked, I
I have a page with a button that when I click, it retrieves data
I have a ASP.NET page with an asp:button that is not visible. I can't
I have a button on an ASP.Net page that will call Response.Redirect back to

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.