Reputation: 5341
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
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