nKognito
nKognito

Reputation: 6363

jQuery's ajaxStart

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

Upvotes: 0

Views: 1252

Answers (2)

xdazz
xdazz

Reputation: 160853

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);
});

Upvotes: 1

Subodh
Subodh

Reputation: 2214

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...');
});

Upvotes: 0

Related Questions