How to implement a jQuery spinner image in an AJAX request

后端 未结 4 2111
無奈伤痛
無奈伤痛 2021-01-04 12:16

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

4条回答
  •  天命终不由人
    2021-01-04 12:48

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

提交回复
热议问题