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);
}
});
}
var $loading = $('#loadingDiv').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
});
where '#loadingDiv' is the spinner gif covering the part of the page or the complete page.
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();
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With