防止用户使用ajax多次请求 的jquery解决方法 参考如下
if (currentAjax) {
if (currentAjax)
currentAjax.abort();
}
///首先设置currentAjax=null
var currentAjax = null;
//结束上一次的请求
function stopAjax() {
//如若上一次AJAX请求未完成,则中止请求
if (currentAjax) {
if (currentAjax)
currentAjax.abort();
}
};
//二级数据请求渲染
$('.xxx').each(function (index, ele) {
$(ele).click(function () {
var id = $(this).attr('data-id')
// repeat = id
if (!$(this).parent().hasClass("active")) {
这里
currentAjax = $.ajax({
url: '' + localStorage.getItem('baseurl')?achTag=' + id + '&t=' + new Date(),
data: '',
dataType: 'json',
timeout: 10000,
headers: {
"App-Version": localStorage.getItem('version'),
'Authorization': r
},
beforeSend: function () {
$('.loading').show()
//在每一次请求之前 将上次一的请求结束掉即可
stopAjax()
},
success: function (info) {}