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.
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.
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!