如何在AJAX请求中实现jQuery微调器图像

Zab*_*abs 11 ajax jquery json

我有一个jQuery AJAX请求,我希望在请求加载时显示ajax spinner gif,然后在请求成功后消失,有人可以建议在我的jquery代码中实现这个的最佳方法:

function updateCart( qty, rowid ){
$.ajax({
        type: "POST",
        url: "/cart/ajax_update_item",
        data: { rowid: rowid, qty: qty },
        dataType: 'json',
        success: function(data){                
            render_cart(data);
        }           
    });
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*een 29

  1. ajax loader获取加载器gif (GIF图像)
  2. 将此图像放在要显示/隐藏的位置.
  3. 在ajax之前,显示此图像.
  4. 完成后,隐藏图像

function updateCart( qty, rowid ){
$('.loaderImage').show();
$.ajax({
        type: "POST",
        url: "/cart/ajax_update_item",
        data: { rowid: rowid, qty: qty },
        dataType: 'json',                         
        success: function(data){                
            render_cart(data);
            $('.loaderImage').hide();
        },
        error: function (response) {
           //Handle error
           $("#progressBar").hide();

    }           
    });
}
Run Code Online (Sandbox Code Playgroud)


Sac*_*our 7

var $loading = $('#loadingDiv').hide();
$(document)
  .ajaxStart(function () {
    $loading.show();
  })
  .ajaxStop(function () {
    $loading.hide();
  });
Run Code Online (Sandbox Code Playgroud)

其中'#loadingDiv'是覆盖页面部分或整个页面的微调器gif.


Car*_*ras 5

我用 gif 图像显示/隐藏 div 。它的作用就像一个魅力:

<script type="text/javascript">

    $("#progressBar").corner();  
    $("#progressBar").show();


    jQuery.ajax({
        url: "../Nexxus/DriveController.aspx",
        type: "GET",
        async: true,
        contentType: "application/x-www-form-urlencoded",
        //data: param,
        success: function (response) {
            //Manage your response.

            //Finished processing, hide the Progress!
            $("#progressBar").hide();
        },
        error: function (response) {
            alert(response.responseText);
            $("#progressBar").hide();

        }
    });

  </script>
Run Code Online (Sandbox Code Playgroud)