You should be able to get the button from the event argument to the button callback function and disable it. Then you save the button in a variable and re-enable the ajax request in the callback.
For example, with HTML:
<div id="dialog"> <div id="message"> Some text </div> </div>
You can do the following:
var n = 0; $("#dialog").dialog({ modal: true, buttons: { "Close": function() { $(this).dialog("close"); }, 'Slow': function(e){ n++; $('#message').html('Fetching...' + n + '...'); var button_clicked = $(e.currentTarget); button_clicked.prop('disabled', true); $.ajax({ url: '/echo/html/', type: 'POST', dataType: 'html', data: { html: 'Updated text', delay: 3 }, success: function(data){ $('#message').html(data); button_clicked.prop('disabled', false); } }); } } });
The clicked button is disabled when the ajax request is started and turned on again when it answers (you really have to add an error handler as well as a colurse). I added a counter to illustrate it - clicking when the button is disabled does nothing.
See how this script works .
Adam
source share