如何从ajaxComplete事件侦听器中排除特定的ajax调用

时间:2014-04-01 19:17:22

标签: javascript jquery ajax

目前,我们正在使用ajaxComplete监听器,该监听器正在调用每次ajax调用后我提到的特定功能。

$(document).ajaxComplete(function () {

    someFunction();
})

有一种情况是在特定的ajax调用之后,我想做某事而不是调用 someFunction()

有没有办法从ajaxComplete中排除特定的ajax调用?

2 个答案:

答案 0 :(得分:5)

以下是如何使用$ .ajaxComplete

中的settings参数的小例子
$.ajax({    
type:"GET",
url:"http://google.com"
});

$.ajax({
    type:"GET",
    url:"https://stackoverflow.com"
});

$(document).ajaxComplete(function(event,xhr,settings){
    console.log("URL",settings.url);
    if(settings.url === "https://stackoverflow.com")
    {
        $(".loadedPage").html("Stackoverflow loaded");
    }
    else if(settings.url === "http://google.com")
    {
        $(".loadedPage").html("Google Loaded");
    }
});

希望这会有所帮助!!

答案 1 :(得分:0)

See the jQuery docs for it

为每个Ajax调用提供事件对象,XMLHttpRequest对象和设置对象。用它来区分你的电话。