I wonder how can I code this:
//if there is any ajax request
$("#loader").css("display","block");
//on success:
$("#loader").css("display","none");
Note :
I am not going to code it again and again in my each ajax request function.
I want it generic so that my script knows if there is any ajax request do $("#loader").css("display","block"); and if there is any ajax success do $("#loader").css("display","none");.
The magical thing you are looking for is jQuery.ajaxStart() and jQuery.ajaxStop(). You might also find jQuery.ajaxComplete() useful.
Example:
You should use the
hide()andshow()methods instead of changing thedisplayCSS attribute.