开发者

how to get the 'guid's nodeValue in my code using google ajax feed api

this is my code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google AJAX Feed API - Simple Example</title>
    <!--<script type="text/javascript" src="http://www.google.com/jsapi"></script>-->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascrip开发者_开发百科t" src='jquery-1.4.2.js'></script>
    <script type="text/javascript">

    google.load("feeds", "1");
    function initialize() {
      var feed = new google.feeds.Feed("http://maps.google.com/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=259e&msa=0&output=georss&msid=109685068115364659392.00048b5b630141d82b83a");

      feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
      feed.load(function(result) {
          if (!result.error) {
            for (var i = 0; i < result.feed.entries.length; i++) {
              var entry = result.feed.entries[i];
             var guid=entry.xmlNode.getElementsByTagName("id") || entry.xmlNode.getElementsByTagName("guid") ||0
            //console.log($('id',entry.xmlNode.xmlDocument)||$('guid',entry.xmlNode.xmlDocument))
            console.log(guid)
            }
          }
        });
  }
    google.setOnLoadCallback(initialize);

    </script>
  </head>
  <body>
    <div id="feed"></div>
  </body>

and my code did not get nothing ,

i use jquery's method text() or html() ,but not too ,

so what can i do .

thanks


Try

$(entry.xmlNode).find('guid').text()

or

$('guid', entry.xmlNode).text()

But, you cannot do:

$(something) || $(somethingElse)

because, the code will never get to $(somethingElse), since $(something) will return a jQuery object even if no match is found. An object (even an empty jQuery object) is truthy, thus the expression is going to be true no matter what the value of $(somethingElse), JavaScript skips evaluating it altogether. It's called short-circuit evaluation. If you do want to find first by "id", then by "guid", then try:

var xml = entry.xmlNode;
var guid = $('id', xml).text() || $('guid', xml).text() || 0;
console.log(guid);

The reason this works is because we are trying to get a string in each step of the expression, and not an object. An empty string is falsy in JavaScript, hence expressions like:

"" || 42; // 42
"" || (40 + 2); // 42

will return the second expression (42) as the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜