javascript - 页面加载时显示 div,完成后隐藏

标签 javascript jquery html

我想在页面加载一些 XML 内容时显示一个带有加载动画的 div。加载后,我想隐藏这个 div。我该怎么做呢?

最佳答案

$.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           
    }
});

关于javascript - 页面加载时显示 div,完成后隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1680650/

相关文章:

javascript - 具有渐变颜色的 Chartjs 圆环图

html - 如何使用 Bootstrap CDN?

html - 文本溢出省略号不适用于 Firefox 和 IE 浏览器中的多行

html - 使用 css 计算内联 block 元素的空间

javascript - 为什么在尝试使用 stringify 将数组转换为 JSON 字符串时出现方括号

javascript - 使用 d3.queue 等待 AJAX 响应

javascript - 匹配多个名称的 Angular 指令

jquery - 如何使用 AJAX 和 JQuery 实现 JSON 数据的 PUT 调用?

javascript - 即使使用 if 语句也获取未定义的值

jquery - 替换 Squarespace commerce 上的文本字符串