0

I want to load the source for multiple HTML pages and parse out part of each page, then take the parsed section and append it to a div on the existing page.

I'm also adding some HTML to the parsed data, which is a link to the original page.

The $.get works, but the link to the original page always shows whatever is the last value of the pages array. I suspect this is a a timing issue; that is, the for loop finishes before the $.get can parse data ... or something.

    var pages=["coralville.html",
           "mercyHomeHealth.html",
           "mercyInpatient.html",
           "steindler.html",
           "mercyMedicalPlaza.html",
           "iowaCityTowncrest.html",
           "tipton.html",
           "williamsburg.html"];

    var hPageName="";
    for(var i=0;i<=pages.length-1;i++){  
        hPageName=pages[i];    
        $.get(hPageName,function (data) {                   
             $(data).find(".third").each(function(){                        
                  var wPage=$(this).parent().parent().find(".oneCol").find(".hdr").html();
            var nData="<div class='staffLoc'><a href='"+hPageName+"'>"+wPage+"</a></div>"+$(this).html();
                    $("#allPeople").append( "<div class='third'>"+nData+"</div>"  );
             });    
        });         
    }
Shawn
  • 3,031
  • 4
  • 26
  • 53
  • Read about js closures, then solve with IIFE. Or, use the full version ajax (`$.ajax()`) and pass in a context – Amit Aug 17 '15 at 22:39
  • found a great solution here http://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop – Shawn Aug 18 '15 at 19:58

0 Answers0