1.設置變量法:
var _thisCondition = true;
$("button").click(function() {
if (!_thisCondition) return false;
_thisCondition = false;
setTimeout(function (){_thisCondition = true; }, 60000);
var url = "test2.php";
$.ajax({
url: url,
type: 'POST',
//async: false,
success: function (msg) {
console.log(msg);
},
error: function () {
console.log("網絡連接失敗");
}
});
})
2.設置button的屬性爲disable:
$("button").click(function () {
$(this).attr('disabled',true);
$.ajax({
url : 'test2.php',
type : 'POST',
async : false,
success : function (msg) {
console.log(msg);
$(this).attr('disabled',false);
},
error : function () {
console.log("網絡連接失敗");
$(this).attr('disabled',false);
}
});
})
以上兩種方法同步異步均可適用