0

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

3
  • you can use global variable to hold ID of button and use it in ajaxStart function. Commented Apr 4, 2012 at 5:59
  • Can u pass the button click event to the function ? Commented Apr 4, 2012 at 6:01
  • @sub_stantial: what do you mean? To which function should I pass the button click event? Commented Apr 4, 2012 at 6:03

2 Answers 2

1

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); }); 
Sign up to request clarification or add additional context in comments.

Comments

0

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

7 Comments

According to jQuery's manual (api.jquery.com/ajaxStart) the callback function does not receives any parameters
My mistake, it should be ajaxSend and not ajaxStart. You can pass events to ajaxSend, check it out here api.jquery.com/ajaxSend
Actually, ajaxStart works fine with parameters, but its target field refers to $('#wait') and not to initial button
what does event.target returns you ?
$('#wait') - the parent div or the source.. I don't know how to call it
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.