I’m wanting to use an AJAX get method to retrieve contents from a page URL. The method works fine, the issue I’m getting is that call returns data before the page is completely loaded
Is there a way I can have the AJAX call only retrieve contents after say 5 seconds for example? (To ensure the page is fully loaded)
You can see on the page below, the page loads and then an additional loading symbol appears which loads the content. I want to retrieve the page data once all content has been loaded
You can use the onload global event handler. The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.
For example
window.onload = function() {
doSomething();
};
And if you need to do the call after 5 secs, do the following
window.onload = function() {
setTimeout(() => {
doSomething();
}, 5000);
};