Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to exclude particular ajax call from ajaxComplete event listener

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?

like image 636
chandu Avatar asked Dec 14 '25 12:12

chandu


1 Answers

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

$.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");
    }
});

Hope this helps!!

like image 151
Akhilesh Sharma Avatar answered Dec 16 '25 04:12

Akhilesh Sharma