最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to exclude particular ajax call from ajaxComplete event listener - Stack Overflow

programmeradmin3浏览0评论

Currently, we are using ajaxComplete listener which is calling specific function which I mentioned after every ajax call happened.

$(document).ajaxComplete(function () {

    someFunction();
})

There is one scenario that after specific ajax call,I want to do something instead of calling someFunction().

Is there a way to exclude a specifc ajax call from ajaxComplete?

Currently, we are using ajaxComplete listener which is calling specific function which I mentioned after every ajax call happened.

$(document).ajaxComplete(function () {

    someFunction();
})

There is one scenario that after specific ajax call,I want to do something instead of calling someFunction().

Is there a way to exclude a specifc ajax call from ajaxComplete?

Share Improve this question edited Apr 1, 2014 at 19:18 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Apr 1, 2014 at 19:17 chanduchandu 2331 gold badge6 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Here is small example how you can use the settings argument in the $.ajaxComplete

$.ajax({    
type:"GET",
url:"http://google."
});

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

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

Hope this helps!!

See the jQuery docs for it

You are supplied with the event object, the XMLHttpRequest object and the settings object for each Ajax call. Use this to differentiate between your calls.

发布评论

评论列表(0)

  1. 暂无评论