I am using such construction:
$('#wait').ajaxStart(function() {
if ($(this).not(':visible'))
$(this).showWarning();
}).ajaxComplete(function() {
if ($(this).is(':visible'))
$(this).hideWarning();
}).ajaxError(function() {
alert('Unexpected error...');
});
And I want to disable submit button every time the user clicks on it. In order to make it universal - I want to do it in ajaxStart method, so is there any way to get the button's id which initialized the request? Thank you
Give all of your submit button a class, for example: submitBtn
, then
$('.submitBtn').ajaxStart(function() {
$(this).prop('disabled', true);
}).ajaxComplete(function() {
$(this).prop('disabled', false);
});
Assuming you can pass the button click event to the function here, you can do it like this :
$('#wait').ajaxSend(function(event) { //pass event object
$(event.target).css('disabled','disabled'); //get event target
if ($(this).not(':visible'))
$(this).showWarning();
}).ajaxComplete(function() {
if ($(this).is(':visible'))
$(this).hideWarning();
}).ajaxError(function() {
alert('Unexpected error...');
});