想要在ajax调用处理时显示加载程序。但隐藏和显示在运行时不起作用。在调试模式下没关系。我试图在ajax上设置超时,但没有结果。
function Rate() {
$("#rate_navigation").hide();
$("#rate_loader").show();
$.ajax({
type: "POST",
url: "url",
data: "data",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
$("#comment_result").html(msg.d);
},
error: AjaxCallError
});
$("#rate_loader").hide();
$("#rate_navigation").show();
}
答案 0 :(得分:4)
beforeSend
和complete
。
请参阅http://api.jquery.com/jQuery.ajax/
function Rate() {
$.ajax({
type: "POST",
url: "url",
data: "data",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
beforeSend: function () {
$("#rate_navigation").hide();
$("#rate_loader").show();
},
complete: function () {
$("#rate_loader").hide();
$("#rate_navigation").show();
},
success: function (msg) {
$("#comment_result").html(msg.d);
},
error: AjaxCallError
});
}
答案 1 :(得分:1)
将这些投入到成功回调中:
success: function (msg) {
$("#rate_loader").hide();
$("#rate_navigation").show();
$("#comment_result").html(msg.d);
},
error: AjaxCallError
});
答案 2 :(得分:1)
将取消隐藏条件置于成功之中
function Rate() {
$("#rate_navigation").hide();
$("#rate_loader").show();
$.ajax({
type: "POST",
url: "url",
data: "data",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
$("#comment_result").html(msg.d);
$("#rate_loader").hide();
$("#rate_navigation").show();
},
error: AjaxCallError
});
}