I am grabbing data through a jQuery Ajax call, and displaying it on the page. I need to wait for both the DOM to load and for the Ajax call to complete before I can use the data to display it on the page. Can an Ajax call ever complete before the DOM has loaded? I'm just trying to determine where I need to put my method that will manipulate the DOM and use the data I'm getting back.
I would wait until the DOM has loaded before making your AJAX call. While it is unlikely that the DOM READY will take longer than the AJAX call, it's just good practice.
You could call and receive an AJAX call before the page loaded to save a tiny bit of time. I would suggest making the script call after you know your element is loaded in the page.
<div id="loadFile"></div> <script> $("#loadFile").load('filename'); </script>
The time saved is probably negligible, though. If you're making an AJAX call before the DOM is loaded, why use AJAX at all? You should try to write some server side code to do the same thing.
©2020 All rights reserved.