jQuery - AjaxStart

The ajaxStart() method is triggered when the request is started. The demo shows a loading section while the request is being made.

http://www.w3schools.com/jquery/ajax_ajaxstart.asp

Loading.....


$(document).ready(function ()
{
    $("#loading").hide();

    $("#btnStart").click(function ()
    {
        $("#request-response").load("ajax-sample.txt");
    });

    // the start of the ajax call will trigger this
    $(document).ajaxStart(function () { ShowStart(); });

    // an error of the ajax call will trigger this
    $(document).ajaxError(function () { ShowError(); });

    // the completion of the ajax call will trigger this
    $(document).ajaxComplete(function () { HideStart(); });

    function ShowStart() { $("#loading").show(); }

    function HideStart() { $("#loading").hide(1000); }

    function ShowError() { $("#request-response").html("An error occurred...must be a bad file name."); }
});