更新时间:2022-10-26 22:46:44
$('#resForm')。验证({
submitHandler:功能(形式){
//禁用提交按钮
$('#btnSubmit按钮')丙(禁用,真正的);
$阿贾克斯({
.....典型AJAX的东西.....
成功:功能(数据){
警报(数据);
$('成功')HTML(数据);
//再次启用备用按钮
$('#btnSubmit按钮')丙(禁用,假);
},
错误:功能(jqXHR,textStatus,errorThrown){
//执行console.log(jqXHR);
}
});
}
});
试试这个
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.
$('#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