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
I do it showing/hiding a div with gif image. It works like a charm:
<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>
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();
}
});
}
On Preloaders.net you can find a very open code along with all the explanations both in pure JavaScript and JQuery formats. You can get the loader images there too