views:

140

answers:

1

I user jquery.ajax call to controller of asp.net mvc... I would like to show a loading indicator.. I tried this but that doesn't seem to work...

<div class="loading" style="padding-left:5px; margin-bottom:5px;display:none;">
      Loading...&nbsp
</div>

and my jquery ajax call looks like this,

function getMaterials(currentPage) {
    $.ajax({
    url: "Materials/GetMaterials",
        data: {'currentPage': (currentPage + 1) ,'pageSize':5},
        contentType: "application/json; charset=utf-8",
        global: false,
        async: false,
        dataType: "json",
        success: function(data) {
            var divs = '';
            $("#ResultsDiv").empty();
            $.each(data.Results, function() {
                //my logic here....              
                $(".loading").bind("ajaxStart", function() {
                $(this).show();
                }).bind("ajaxStop", function() {
                $(this).hide();
                });
            }
    });
    return false;
}

My loading indicator doen't seem to showup.. ANy suggestion....

+2  A: 

using .ajax() you should just call:

beforeSend:  function(xmlHttpRequest){
    // show anything here
}

and

complete:  function(xmlHttpRequest, status){
    // hide it again
}

Kind Regards

--Andy

jAndy