我有这个:
jQuery.ajaxSetup({
async:false,
dataType: 'json',
beforeSend: function(){
$(this).next('.ajaxLoader').show();
console.log($(this));
},
complete: function(){
$(this).next('.ajaxLoader').hide();
}
});
但问题是$(this)
指向' body'在beforeSend中,它指向完整函数中的jQuery对象。我需要两个函数' $(this)来引用当前正在使用的点击处理程序。
jquery ajax - global settings. Is it possible to know what event/element trigger the ajax call?
答案 0 :(得分:0)
根据jquery ajax - global settings. Is it possible to know what event/element trigger the ajax call?
更新答案var $this;
jQuery.ajaxSetup({
async:false,
dataType: 'json',
beforeSend: function(jqXHR, settings){
$this = settings.context.element;
$this.next('.ajaxLoader').show();
console.log($this);
},
complete: function(){
$this.next('.ajaxLoader').hide();
}
});