Ajax after page fully loaded

Asked

Viewed 278 times

1

I have a very slow code running on the server side, to avoid the delay in rendering the page, I decided to call the function via ajax after the page loaded, I used both ways but both did not work:

With the $(document).ready the page is displayed, but files from fonts (Google Fonts) and icons are loaded after.

$(document).ready(function() {
    $.ajax({ ... });
});

Already with the $(window).bind the page is fully displayed after completing the function.

$(window).bind("load", function() {
    $.ajax({ ... });
});
  • You want to call an ajax after the fonts are loaded eh this?

  • Exactly @Leonard

  • Take a look at this topical It seems that the solution does not work well in all browsers, so the recommended was to use setTimeout to achieve the desired result.

  • 1

    Can you put the code you have now to load the fonts? If they are inside the <head> carry before the domready or load

  • 1

    Is using the $(window).bind("load", ... at the top of the page? I think it has to be to work properly.

  • I didn’t quite understand the problem. The variation with bind gives the result you want?

  • 1

    Place the ajax at the bottom of the page

Show 2 more comments

1 answer

1

The ready method runs once the DOM is completed, it does not mean that your page is fully rendered.

Try using the following code:

window.onload = function() { <seucódigoaqui> };

Browser other questions tagged

You are not signed in. Login or sign up in order to post.