jquery - Problems processing an XML file -
i'm using jquery retrieve xml file. xml file dynamically generated (php) based upon parameters passed jquery. example, request information on 3 ids (in example: 0zjb001, 5yh043, 9tq987). returned xml file contains list of requested ids , found items. i'm changing span contents depending upon these values. i've got working fine, except when less items returned requested. so, if 3 items requested , 2 returned, jquery each statement executed twice. instead, need execute each itemid , retrieve details corresponding asin item, or otherwise update default details.
sample xml file format (not exact, it's simplified):
<itemlookupresponse> <items> <request> <itemlookuprequest> <itemid>0zjb001</itemid> <itemid>5yh043</itemid> <itemid>9tq987</itemid> <variationpage>all</variationpage> </itemlookuprequest> </request> <item> <asin>0zjb001</asin> <offersummary> <totalnew>0</totalnew> <totalused>0</totalused> <totalcollectible>0</totalcollectible> <totalrefurbished>0</totalrefurbished> </offersummary> </item> <item> <asin>9tq987</asin> <offersummary> <lowestnewprice> <amount>1000</amount> <currencycode>usd</currencycode> <formattedprice>$10.00</formattedprice> </lowestnewprice> <totalnew>1</totalnew> <totalused>0</totalused> <totalcollectible>0</totalcollectible> <totalrefurbished>0</totalrefurbished> </offersummary> </item> </items> </itemlookupresponse>
so end result (in "pseudo code"):
foreach(items) { if(exists itemid && asin) { //update span price } else { //update span default text } }
try
function callback(xml){ var itemids = xml.find('request itemlookuprequest itemid'); var items = xml.find('items > item'); itemids.each(function(idx, itemid){ var item = items.filter(function(idx, item){ return $(item).children('asin').text() == itemid; }); if(item.length){ //update span item.find('formattedprice').text() } else { //update span default price } }) }
Comments
Post a Comment