我想在 .load() 之前显示“LoaderMain”div,并在全部完成后隐藏“LoaderMain”。当我取消注释我的显示/隐藏时,它永远不会显示。
$('#content').html('');
//$('#LoaderMain').show();
$("#content").load(url, function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#content").html(msg + xhr.status + " " + xhr.statusText);
}
});
//$('#LoaderMain').hide();
最佳答案
将 $('#LoaderMain').hide();
放入回调函数中。
例如:
$('#content').html('');
$('#LoaderMain').show();
$("#content").load(url, function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#content").html(msg + xhr.status + " " + xhr.statusText);
}
$('#LoaderMain').hide();
});
关于javascript - 在 Ajax .load() 期间显示/隐藏 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17795622/