gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:28:32 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com