Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent .ajaxStart() from executing on a specific Ajax Request

I have a loading div or loader that should show up during Ajax Requests.

$('#loadingDiv').ajaxStart(function () {
        $(this).show();
    }).ajaxComplete(function () {
        $(this).hide();
    });

I want the loader to show up during all Ajax Requests, but prevent it on a particular request.

I tried the following:

$.ajax({
                url: 'Handler.ashx',
                success: function (msg, status, xhr) {
                    $('#loadingDiv').hide();
}.....

But the div shows up then disappears, I don't want it to show up at all.

like image 931
Ali Bassam Avatar asked Dec 16 '22 07:12

Ali Bassam


1 Answers

Set global to false when making the request:

$.ajax({
    url: 'Handler.ashx',
    global: false,
    ...
});

See the Ajax.Events docs.

like image 74
Douglas Avatar answered Feb 13 '23 06:02

Douglas