在页面加载时显示div,完成后隐藏
问题描述:
我想在页面加载一些XML内容时在页面上显示一个 div
加载动画。一旦它加载,我想隐藏这个div。
I want to show a div
with a loading animation over my page while the page loads some XML content. Once its loaded, I want to hide this div. How can I go about doing this?
答
$.ajax({
url: '/test.xml',
beforeSend: function(XMLHttpRequest) {
// Show the div before sending the request
$('#load').show();
},
complete: function(XMLHttpRequest, textStatus) {
// Hide the div no matter if the call succeeded or not
$('#load').hide();
},
success: function(xml) {
// if the request succeeds do something with the received XML
}
});