D-W
D-W

Reputation: 5341

Jquery, ASP.NET MVC Async task?

Simple button, How do I disable the button immediately? my api call is not async, but I dont want user submitting multiple requests?

Example? Search

    function GetClient() {
    $("#btnSubmitCode").prop("disabled",true);

    //Ajax call here

//takes a few seconds to go and get info from api
}

Upvotes: 0

Views: 47

Answers (1)

Renzo Robles
Renzo Robles

Reputation: 714

You could use ajax call setup for disable the button.

$.post(your_api_url, { data,
    beforeSend: function() {
        $("#btnSubmitCode").prop("disabled",true);
    },
    error: function() {
        $("#btnSubmitCode").prop("disabled",false);
    },
    success: function(data) {
        $("#btnSubmitCode").prop("disabled",false);    
    }
});

Upvotes: 1

Related Questions