防刷机制一:按钮点击到发送接口请求间隔1-3s,在间隔过程中如果又再次点击按钮,则从头再来,前面计时等待的操作清除
防刷机制二:按钮点击即发送接口请求,请求过程中按钮点击无效,直到接口请求的数据返回或间隔一定时间后,再解禁按钮
// 防刷机制一:
var foo = {
timeout: null,
getData: function() {
var _this = this;
clearTimeout(_this.timeout);
_this.timeout = setTimeout(function() {
clearTimeout(_this.timeout);
$.ajax({ ...... });
},1000);
}
}
// 防刷机制二:
var foo = {
statue: true,
getData: function() {
var _this = this;
if(_this.statue) {
_this.status = false;
$.ajax({
type: "get",
url: "xxxx",
success: res => {
_this.status = true;
}
});
}