如何在AJAX请求中实现jQuery微调器图像 [英] How to implement a jQuery spinner image in an AJAX request

查看:164
本文介绍了如何在AJAX请求中实现jQuery微调器图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an jQuery AJAX request which I want to have display an ajax spinner gif while the request loads and then disappear once the request is successful, can anyone suggest the best method to implement this into my jquery code below:

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);
        }           
    });
}

推荐答案

  1. ajax加载器 (GIF图片)
  2. 中获取加载器gif.
  3. 将此图像放置在您要显示/隐藏的位置.
  4. 在ajax之前,显示此图像.
  5. 完成后,隐藏图像
  1. Get a loader gif from ajax loader (GIF images)
  2. Place this image where you want to show/hide.
  3. Before the ajax, show this image.
  4. Once completed, hide the image


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();

    }           
    });
}

这篇关于如何在AJAX请求中实现jQuery微调器图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆