Chrome AJAX on page-load causes “busy cursor” to remain

前端 未结 6 1693
情话喂你
情话喂你 2020-12-30 06:12

In Google Chrome, AJAX called within $(function(){....}); seems to keep the page loading.

I have a site with a few pages with tabs. Because I\'m using cheap godaddy

6条回答
  •  无人及你
    2020-12-30 06:40

    Update

    This solution will not work for Chrome. It stops the loading indicator only when all requests made before window load have completed. The only solution appears to be to get it to make the request after window load, but as far as I know, this is only possible with setTimeout, which isn't great.


    Update

    To get around the pointer issue in Chrome, you could set the cursor style as shown in this fiddle. It's a bit hacky and it doesn't address the issue of the loading indicator at the top of the tab.


    The loading indicator will be present in browsers until the page has loaded (window's load event). In $(function(){someCode();});, someCode is executed when the DOM load event is triggered (when all content has been parsed and inserted into the DOM, before page load). The execution of JavaScript at this point blocks the window's load event from firing, and so prevents the loading indicator from stopping. Note that image loading also blocks the window's load event.

    Instead, you could try $(window).load(function(){someCode();});. In this example, someCode is executed when the window's load event is triggered. This is at the point where the browser's loading indicator stops.

    So, instead of:

    $(function(){
        /*AJAX CODE HERE */
    });
    

    Try:

    $(window).load(function(){
        /*AJAX CODE HERE */
    });
    

    Note that this may cause your JavaScript to begin execution later, which may not be desirable.

提交回复
热议问题