Showing a div while page is loading, hiding when its done

后端 未结 1 541
礼貌的吻别
礼貌的吻别 2021-02-11 08:12

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 doin

相关标签:
1条回答
  • 2021-02-11 08:47
    $.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           
        }
    });
    
    0 讨论(0)
提交回复
热议问题