我创建了一个$ .ajaxSetup来拦截我在整个应用程序中通过$ .ajax执行的所有ajax调用。使用$ .ajaxSetup我可以跨应用程序显示和隐藏所有ajax调用的微调器。
$.ajaxSetup({
beforeSend: function (xhr) {
$('#loader').removeClass('display-none');
},
complete:function(xhr,status){
$('#loader').addClass('display-none');
}
});
我想获取网址,以便我可以检查并阻止此网址的微调器:http://graph.facebook.com
答案 0 :(得分:1)
您可以使用this.url
并实现您想要的目标。
$.ajaxSetup({
beforeSend: function () {
if(this.url != 'http://graph.facebook.com'){
$('#loader').removeClass('display-none');
}
},
complete:function(xhr,status){
$('#loader').addClass('display-none');
}
});
答案 1 :(得分:0)
如果我正确理解你的问题,你想从ajaxSetup中获取ajax调用的url。 您可能想要使用预过滤器,如下所示:
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
$url = options.url;
});