【发布时间】:2010-02-16 11:45:41
【问题描述】:
我在 ajax 调用后解析 xml 文件以“获取”xml 文件。我正在尝试返回其中一个节点(使用 find 方法)。但是它不会返回 ie 中的值 - 在 Firefox 中很好。我正在发出警报以测试该值,但它只是返回空白。下面是代码:
function autoFeedGetter () {
$('#notifyBox').empty();
$.ajax ({
type: "GET",
url: "actual url removed",
datatype: "xml",
success: checkNoteDate
});
};
// get time date saved to fullDateTime Variable
function checkNoteDate (xml) {
var noteDate = 'Not';
var lastSplit = 'Not';
// get published date from feed
noteDate = $(xml).find('entry published:eq(0)').text();
alert(noteDate);
}
问题似乎出在这个方法上——noteDate = $(xml).find('entry published:eq(0)').text();
但是我已经尝试了其他各种版本,包括: noteDate = $(xml).find('entry:first published').text();
如果有人有任何信息将不胜感激。
示例 xml
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:ibmfs="http://purl.org/net/ibmfeedsvc/feedsvc/1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<title>Notifications</title>
<link rel="alternate" href="http://www.#.com/notifyme" />
<subtitle>This feed has been created using ROME (Java syndication utilities)</subtitle>
<entry>
<title>This is another test message !</title>
<link rel="alternate" href="http://#/cwweb/" />
<author>
<name>ContentWatch</name>
</author>
<updated>2010-02-12T14:22:19Z</updated>
<published>2010-02-12T14:22:19Z</published>
<dc:creator>ContentWatch</dc:creator>
<dc:date>2010-02-12T14:22:19Z</dc:date>
</entry>
<entry>
<title>You got mail!</title>
<link rel="alternate" href="http://#/cwweb/" />
<author>
<name>ContentWatch</name>
</author>
<updated>2010-02-10T12:11:49Z</updated>
<published>2010-02-10T12:11:49Z</published>
<dc:creator>ContentWatch</dc:creator>
<dc:date>2010-02-10T12:11:49Z</dc:date>
</entry>
</feed>
已删除敏感数据 - 我能够成功解析完整数据但无法检索一个元素 - 例如我正在寻找第一个发布日期
【问题讨论】:
-
你能举一个你正在下载的xml的例子吗?
-
可能只是一个错字,但
.ajax()的datatype选项应该是dataType,而不是datatype。 -
Cheers Crescent Fresh 确实是一个很好发现的错字:-)
-
@jonnyhitek 你找到这个问题的答案了吗,因为我也有同样的问题
标签: javascript jquery xml