【问题标题】:jquery .find() does not find an xml nodejquery .find() 找不到 xml 节点
【发布时间】:2012-11-27 09:58:34
【问题描述】:

无论我尝试什么,我都无法在 .ajax 响应中找到 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') 确实进入了 each 循环。我不明白为什么它无法解析$(response).find('ctatt').find('eta')

【问题讨论】:

  • 你从哪里得到那个 XML,你用$.parseXML 把它解析为 XML 吗?

标签: jquery xml ajax parsing


【解决方案1】:
var xml = $.parseXML(response);

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

FIDDLE

【讨论】:

  • XML 从 Web 服务返回。此代码在 Fiddle 中完美运行。但是,它不会进入Phonegap应用程序中的每个循环。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-24
  • 2013-09-21
  • 1970-01-01
  • 2011-01-13
  • 2021-10-02
  • 2018-09-09
相关资源
最近更新 更多