Jump to content
brock82

load xml using jquery - getting duplicate items

Recommended Posts

I'm trying to load an xml file into an html file using jquery... i'm using jquery bc the site is built in Adobe's Business Catalyst and doesnt allow for any server-side scripting languages.

 

The XML fIle is broken down into five sections - Corporation Builder Subdivision Plan and Spec- with child nodes within themThe following node names are in the following format (Parent Child). The data that I am trying to display are the: "Builder BrandName", "Spec SpecStreet1", "Spec SpecPrice", "Subdivision SubParentName", "Plan Description", "Spec SpecElevationImage", "Spec SpecBedrooms", "Spec SpecBaths", "Spec SpecSqft", "Spec SpecGarage"So far I've managed to .find and .append all the information in the correct format within its appropriate div with one exception - The data is being repeated around 78 times. Where there should only be one version of each address. So my question is:What can i do to continue displaying the data on my page (http://www.fallsatimperialoaks.com/home-inventory/index_copy.html) without having the data repeated?The XML File is located at http://www.fallsatimperialoaks.com/I8959.xml

<script type="text/javascript">    $(document).ready(function(){        $.ajax({            type:"GET",            url:"/I8959.xml",            dataType:"xml",            success: function(data){        $('#load').fadeOut();                       $(data).find("Builder").each(function(){                                    var Brandname = $(this).find("BrandName").text();                var Subdivision = $(this).find("Subdivision SubParentName").text();                              $(data).find("Plan").each(function(){                                           var Description = $(this).find("Description").text();                              $(data).find("Spec").each(function(){                                var Address = $(this).find("Spec SpecStreet1").text();                var Price = $(this).find("Spec SpecPrice").text();                var Image = $(this).find("Spec SpecElevationImage").text() + '" width="220" height="124" alt="' + $(this).find("Spec SpecStreet1").text();                             var Beds = $(this).find("Spec SpecBedrooms").text();                var Baths = $(this).find("Spec SpecBaths").text();                var Sqft = $(this).find("Spec SpecSqft").text();                var Garage = $(this).find("Spec SpecGarage").text();//Append to homecontainer                             $("#homecontainer").append(' <div class="address"> ' + Address + ' <br><span>Section: ' + Subdivision + '</span>' + '</div>' + ' <div class="price"> $' + Price + ' <br><span> ' + Brandname + ' </span>' + '</div>'  + '<div class="clearboth"></div>' +  ' <div class="home-image"><img src="' + Image + '"/>' +'</div>' + ' <div class="home-description"> ' + Description + '</div>' +  '<div class="clearboth"></div>');            $("#homecontainer").append(' <div class="stats"><div class="beds"><img alt="" src="/images/ico-beds.png" style="border: 0px; width:22px;" /> ' + Beds + ' Bedroom(s)</div><div class="baths"><img alt="" src="/images/ico-baths.png" style="border: 0px; width:22px;" /> ' + Baths + ' Bath(s)</div><div class="sqft"><img alt="" src="/images/ico-sqft.png" style="border: 0px; width:22px;" /> ' + Sqft + ' Sq. Ft.</div><div class="garage"><img alt="" src="/images/ico-garage.png" style="border: 0px; width:22px;" /> ' + Garage + ' Car Garage</div></div>');                                        }); //End Data Function "Spec"                      }); //End Data Function "Plan"                    }); //End Data Function "Builder"                },            error:function(){            $("#homecontainer").text('Failed to get feed');        }    });});                   </script>

Any help is appreciated! 

Share this post


Link to post
Share on other sites

Inside the function that runs for each Builder element, you should probably be using $(this) instead of $(data). You don't want to search the entire file, just the one node.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...