<script>
    $.ajaxSetup({
        beforeSend:function(){
            // show gif here, eg:
            $("#ajax-loading").show();
        },
        complete:function(){
            // hide gif here, eg:
            $("#ajax-loading").hide();
        }
    });
</script>
<div id="ajax-loading" hidden></div>