2012-12-10 54 views
1

無論我嘗試什麼,我都無法在.ajax響應中找到XML節點。jquery .find()找不到xml節點

<?xml version="1.0" encoding="utf-8"?> 
<ctatt> 
    <tmst>20121209 09:58:14</tmst> 
    <errCd>0</errCd> 
    <errNm /> 
    <eta> 
     <staId>40970</staId> 
     <stpId>30188</stpId> 
     <staNm>Cicero</staNm> 
     <stpDe>Service toward Forest Park</stpDe> 
     <rn>105</rn> 
     <rt>Blue</rt> 
     <destSt>0</destSt> 
     <destNm>Forest Park</destNm> 
     <trDr>5</trDr> 
     <prdt>20121209 09:57:40</prdt> 
     <arrT>20121209 10:00:40</arrT> 
     <isApp>0</isApp> 
     <isSch>0</isSch> 
     <isDly>0</isDly> 
     <isFlt>0</isFlt> 
     <flags /> 
    </eta> 
</ctatt> 

$(response).find('ctatt').find('eta').each(function(){});將不會找到ela節點。它永遠不會進入每個循環。

$(response).find('ctatt').find('tmst')$(response).find('ctatt').find('errCd')確實進入每個循環。我不明白爲什麼它不能解析$(response).find('ctatt').find('eta')

+1

你從哪裏得到的是XML,你分析它爲XML與[** $ parseXML **](HTTP:/ /api.jquery.com/jQuery.parseXML/)? – adeneo

回答

0
var xml = $.parseXML(response); 

$(xml).find('ctatt').find('eta').each(function(i,elem){ 
    console.log(elem); 
}); 

FIDDLE

+0

XML是從Web服務返回的。這段代碼在小提琴中完美運作。但是,它不會進入Phonegap應用程序的每個循環。 –