在页面加载时显示div,在完成时隐藏

mrp*_*atg 1 html javascript jquery

我希望div在页面加载一些XML内容时在我的页面上显示加载动画.一旦加载,我想隐藏这个div.我该怎么做呢?

Dar*_*rov 8

$.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           
    }
});
Run Code Online (Sandbox Code Playgroud)