我有一个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
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)
var $loading = $('#loadingDiv').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
});
Run Code Online (Sandbox Code Playgroud)
其中'#loadingDiv'是覆盖页面部分或整个页面的微调器gif.
我用 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)
| 归档时间: |
|
| 查看次数: |
46007 次 |
| 最近记录: |