Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  181] [ 3]  / answers: 1 / hits: 37857  / 11 Years ago, mon, october 7, 2013, 12:00:00

I am trying to achieve the scenario of disabling a button on clicking it, and then enabling it again after the ajax request has completed successfully.



The below is the snippet of my code.



Form



<button id=btnSubmit type=submit class=btn btn-warning btn-lg>Submit!</button>


Javascript



$('#resForm').validate({
// disable submit button
$('#btnSubmit').prop('disabled', true);

submitHandler: function(form) {
$.ajax({
..... typical ajax stuff .....
success: function(data) {
alert(data);
$('success').html(data);
// enable reserve button again
$('#btnSubmit').prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
// console.log(jqXHR);
}
});
}
});


It doesn't work. And checking my console on Chrome tells me Uncaught SyntaxError: Unexpected token (. It feels like it's a stupid mistake somewhere and I can't figure it out. I have read that prop is meant for jQuery 1.6.1 and later and I am on 1.8.3.


More From » jquery

 Answers
7
$('#resForm').validate({


submitHandler: function(form) {
// disable submit button
$('#btnSubmit').prop('disabled', true);
$.ajax({
..... typical ajax stuff .....
success: function(data) {
alert(data);
$('success').html(data);
// enable reserve button again
$('#btnSubmit').prop('disabled', false);
},
error: function (jqXHR, textStatus, errorThrown) {
// console.log(jqXHR);
}
});
}
});


Try this


[#75180] Saturday, October 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wyattkennyc

Total Points: 650
Total Questions: 102
Total Answers: 90

Location: Monaco
Member since Mon, May 23, 2022
2 Years ago
;