user2779312
user2779312

Reputation: 661

Ajax calls - global animation handler

On my ASP.NET MVC website I have the following inside my layout.cshtml:

$(document).ajaxStart(function () {
    $(".modal").fadeIn(300)
});

$(document).ajaxStop(function () {
    $(".modal").fadeOut(300);
});

The .modal class is basically a div that shows a gif with a typical animation inside.

So I don't want this animation to appear on all my ajax calls. Is there anyway to know which specific ajax call is raising this event?

The other option would be to manually handle it inside all my ajax calls, but since I only have 1 ajax call that I want to exclude it doesn't make sense.

Thanks

Upvotes: 0

Views: 79

Answers (2)

shenku
shenku

Reputation: 12448

On your individual call, set the global option for the ajax call to false:

$.ajax({
    global: false,     // this will prevent start from being called.
});

Upvotes: 1

jPO
jPO

Reputation: 2552

I have faced a similar problem before and I found a solution here on stackoverflow, but I can't remember or find exactly the same solution as I found before but you might find this answer interesting JavaScript detect an AJAX event and if that isn't enough, then I'd extend the ajax calls in whichever js framework you are using.

Upvotes: 0

Related Questions