How do I print an array using jQuery from xml data?

john020

New Member
I'm just trying to print a jQuery array from an XML file. Here's my code. I'm trying to print stockList as you can see from the html code. Also, did I do the onBodyLoad correctly?HTML:\[code\] <body onload="onBodyLoad()"> <div id="stockList"></div> <br /> <br /> <br /> <div id="stockInfo"></div> </body>\[/code\]jQuery:\[code\]$(document).ready(function () { $.ajax({ type: "GET", url: "stocks.xml", dataType: "xml", success: function (onBodyLoad) { var stocklist = new Array(); var stockinfo = new Array(); $(onBodyLoad).find('Stock').each(function () { var company = $(this).find('Company').text(); var market = $(this).find('Market').text(); var sector = $(this).find('Sector').text(); var price = $(this).find('Price').text(); $(onBodyLoad).find('YearRange').each(function () { var low = $(this).find('Low').text(); var high = $(this).find('High').text(); }); $(onBodyLoad).find('Dividend').each(function () { var amount = $(this).find('Amount').text(); var yieldx = $(this).find('Yield').text(); var frequency = $(this).find('Frequency').text(); }); stocklist = $(company); $('#stockList').append('<div><p>' + stocklist + '</p></div'); }); } });});\[/code\]XML:\[code\]<Stock symbol="GOOG"> <Company>Google</Company> <Market>NASDAQ</Market> <Sector>Software</Sector> <Price>$487.80</Price> <YearRange> <Low>$331.55</Low> <High>$488.50</High> </YearRange> <Dividend available="false"/></Stock><Stock symbol="BA"> <Company>Boeing Company</Company> <Market>NYSE</Market> <Sector>Aerospace</Sector> <Price>$79.05</Price> <YearRange> <Low>$63.70</Low> <High>$89.58</High> </YearRange> <Dividend available="true"> <Amount>$1.20</Amount> <Yield>$1.50</Yield> <Frequency>QTR</Frequency> </Dividend></Stock>\[/code\]Desired output:
Google
Boeing Company
 
Back
Top