Loading animation doesn't show up until after ajax call completes in Safari/Chrome

后端 未结 2 747
执念已碎
执念已碎 2021-01-24 12:37

I\'ve run into a problem that I haven\'t been able to find a solution to yet.

I\'m creating a resource booking application which uses AJAX to process information given b

2条回答
  •  面向向阳花
    2021-01-24 13:12

    You could set a callback for the image load event and then only execute the ajax POST when it has loaded. Like so...

    function processBooking(selection, responseID, formElement, removing, fromManager, resourceType) {
        //...some stuff
        startLoading(function(){
            sendAsyncRequest(url,postData,callback,false);
        });
        //...some more stuff
    }
    
    function startLoading(callback) {
        document.getElementById("container").style.opacity = "0.2";
        document.getElementById("cover").style.display = "block";
        var img = new Image();
        img.onload=callback;
        img.src="/intranet/images/ajax-loader.gif";
        var newDiv = document.createElement("div");
    
        newDiv.setAttribute("id", "loading");
        newDiv.style.height = 120 + "px";
        newDiv.style.width = 350 + "px";
    
        newDiv.innerHTML = "


    Processing database...

    "; document.body.appendChild(newDiv); ignoreClicks = true; }

提交回复
热议问题