对于我能够找到解决方案的好答案。
我最终想要本地化" loading"要基于元素ID显示的图像。全局ajaxStart()和ajaxComplete()功能不会处理本地事件。所以我用超时切换到beforeSend()函数:
$('.item').click( function (e) {
e.preventDefault();
var theID = $(this).attr('data');
var theInfo = $('.holder#h' + theID);
var loader = $('.waiting#w' + theID);
$('.holder').slideUp(); //closes any open data holders
var ajaxLoadTimeout;
if (!$(theInfo).hasClass('opened')) {
$(this).addClass('clicked');
$(theInfo).addClass('opened');
$(theInfo).html(''); //removes any existing data
$.ajax({
url: '_core/inc/getdata.php',
type: 'POST',
data: ({dataid: theID}),
dataType: 'html',
//shows LOCAL loader before ajax is sent
//but waits 3 milliseconds before doing so
//most of the ajax calls take less than 3ms
//without the timeOut the loader "flashes" for a milisecond
beforeSend : function() {
ajaxLoadTimeout = setTimeout(function() {
$(loader).show();
}, 300);
},
success: function(data) {
$(theInfo).html(data);
//Hides LOCAL loader upon ajax success
clearTimeout(ajaxLoadTimeout);
$(loader).hide();
},
complete: function(){
$(theinfo).slideDown();
}
});
} else {
$(this).removeClass('clicked');
$(theInfo).removeClass('opened').slideUp();
}
});
相关的PHP / HTML:
echo '
'.$this_title.'
';
CSS:.waiting { discplay: none; }
我不知道这是对还是错,但似乎在这里按预期工作。
如果该项目的加载时间超过几毫秒,它允许字体真棒图标出现在项目标题旁边。