Link to home
Start Free TrialLog in
Avatar of Arnold Layne
Arnold LayneFlag for United States of America

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.

$(document).ready(function () {
    initializeMap();
    $.when($("#orders").load("datadisp.aspx")).done(function () {
        setMarkers();
    });

Open in new window



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.
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Hi,

.load accepts a callback function in the parameters, so you could do the following:

    $("#orders").load("datadisp.aspx", function () {
        setMarkers();
    });

Open in new window


Giannis
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial