2010-02-16 16 views
0

我解析一个XML文件后,ajax调用'获取'的XML文件。我试图返回其中一个节点(使用find方法)。但它不会返回IE中的值 - 在Firefox中罚款。我正在做一个警报来测试这个值,它只是回到空白。下面是代码:jQuery解析xml不返回数据在ie

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(“条目:首次发布')。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> 

敏感数据中去除 - 我能够成功地解析在充分的数据,但不能检索一个元件 - 例如我正在寻找第一个发布的日期

+0

你能举一个你正在下载的xml的例子吗? –

+0

可能只是一个拼写错误,但'.ajax()'的'datatype'选项应该是'dataType',而不是'datatype'。 –

+0

Cheers Crescent Fresh确实发现了一个错字:-) – jonnyhitek

回答

0

看看andrea varnier的回复在底部http://groups.google.com/group/jquery-en/browse_thread/thread/adb2b047f3761179?pli=1,它似乎IE浏览器不能处理从本地机器加载的XML文件。还有一种解决方案邮资那里,如果你不想依赖它只是工作时您部署页:

success: function(xmlData){ 
var data; 
if (typeof xmlData == 'string') { 
    data = new ActiveXObject('Microsoft.XMLDOM'); 
    data.async = false; 
    data.loadXML(xmlData); 
} else { 
    data = xmlData; 
} 

因此,它看起来像IE已经离开了XML作为一个字符串,这样的方法负载它变成了一个XML文档对象。然后你可以在该对象上使用jQuery。

+0

Cheers paul我已经试过了noteDate = $(xml).find('entry published :first')。text() 这是在Firefox中罚款,但返回空白即将尝试你的第二次消化,让你知道我是如何相处。欢呼声 – jonnyhitek

+0

嘿保罗仍然没有工作,即:( – jonnyhitek

+0

我已经编辑了答案,我在Google上找到了一个潜在的解决方案 –