Jquery bind AjaxStart and AjaxEnd to document ready function
$(document).ready(function(){
$(document).ajaxStart(function() {
$('#loading').fadeIn(500);
}).ajaxStop(function() {
$('#loading').fadeOut(500);
});
})