Arnold Layne
asked on
$.when().done() not working as expected
I need to load html on to a page via jquery ajax. Then, after the html has loaded, I want to parse it for certain data that will be in the loaded html, and use it to create map markers. So I need the load method to act synchronously, so that the html is definitely loaded before my setMarkers() method tries to parse it.
I thought the current set up that I have is supposed to do exactly that, but I can tell from the debugger that setMarkers() is still being called before the load has completed, because when I put a breakpoint on setMarkers() and inspect the html, I can tell it has not loaded yet. Can somebody show me the right way to solve this problem? Thanks.
$(document).ready(function () {
initializeMap();
$.when($("#orders").load("datadisp.aspx")).done(function () {
setMarkers();
});
I thought the current set up that I have is supposed to do exactly that, but I can tell from the debugger that setMarkers() is still being called before the load has completed, because when I put a breakpoint on setMarkers() and inspect the html, I can tell it has not loaded yet. Can somebody show me the right way to solve this problem? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
.load accepts a callback function in the parameters, so you could do the following:
Open in new window
Giannis