0

Here is my ajax call:

 $.ajax({
                        url: "AutoRFQ_Vendors_ST.aspx/BindVesselGrid",
                        type: "POST",
                        timeout: 3000,
                        data: JSON.stringify(sendingdata),                  
                        contentType: "application/json",
                        success: function (data) {
    //do something
    }

Here is my CSS loader:

  ajaxStart: function () { $body.addClass("loading"); },
            ajaxStop: function () { $body.removeClass("loading"); }

When I make an ajax call which responds d:'' an empty string but my ajaxstop: event is not firing.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Arun Nandha
  • 47
  • 1
  • 9

2 Answers2

0

You have to hide your loader on ajax() complete like:

ajax({
    complete: function(){
        $body.removeClass("loading");
    }
});

complete executes after either the success or error callback were executed.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

You need to understand that the ajaxStart and the ajaxStop events falls under global event handlers in jQuery. Hence you need to hook them to document instead of having in your $ajax call.

You need to rewrite your code as,

$(document)
 .ajaxStart(function () {
   $body.addClass("loading");
 })
.ajaxStop(function () {
   $body.removeClass("loading");
});

Hope this helps!

David R
  • 14,711
  • 7
  • 54
  • 72