php - jQuery find() 在 Google Chrome 中返回空字符串

标签 php jquery ajax firefox google-chrome

我正在使用 jQuery 设置一个 Ajax 请求,该请求从 PHP 脚本中获取 XML 提要,然后从提要中解析一些信息并将其插入到 DOM 中。 在 Firefox 中运行良好;但是,在 Chrome 中,我的 title 元素得到一个空字符串。

这是 Ajax 请求的基本设置:

$.get('feed.php', function(oXmlDoc) {
  $(oXmlDoc).find('entry').each(function() {
    $(this).find('title').text();
    $(this).find('id').text();
    // do other work...
  }); 
});

不管怎样,这里是从 feed 中获取数据的 PHP 脚本。我使用 cURL 是因为我要跨域发出请求(并且因为它是针对当前问题的快速但肮脏的解决方案)。

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $str_feed_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($curl);
curl_close($curl);

echo $xml;

XML 数据正确返回,我可以在 Chrome 中看到同级节点的值(例如 ID),但是,无论出于何种原因,我仍然得到一个空字符串title 节点。

编辑:根据要求,这里是相关 XML 的片段:

<entry>
    <id>http://TheAddress.com/feed/01</id>
    <title type="text">The Title of the Post</title>
    <author><name>Tom</name></author>
    <published>2009-11-05T13:46:44Z</published>
    <updated>2009-11-05T14:02:19Z</updated>
    <summary type="html">...</summary>
</entry>

最佳答案

示例 XML 中的页面的标题中有一个 HTML 实体。这可能会导致问题。这是blog post我在这个问题上发现了。

我想知道其他特殊字符是否也是如此......

主页标题如下所示:

<title>The Address Hotels + Resorts</title> 

关于php - jQuery find() 在 Google Chrome 中返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1680789/

相关文章:

php - 不使用表单传递或发布输入值

javascript - 将字符串作为函数执行

javascript - 循环json数据然后用php发送到数据库

php - Ajax 中的 RSS 阅读器 : Help with code, 有什么问题/缺失?

php - 如何显示给定 php 组合框中的项目的不同 php 表?

php - Doctrine DQL 条件查询

php - 需要 Google Chrome 扩展程序中网站的文本

php echo mysql数组导致ajax

javascript - 获取 Azure 服务总线的详细信息

ajax - Node.js:基于事件的 cometd 插入定期 ajax 请求?