2010-06-22 86 views
0

我有这样的代码,在装载了mouseenter XML文件,这些文件在Firefox工作:

$(document).ready(function() { 
     $('.invest-port-thumb a').mouseenter(function() { 

       $.get(this.href, function(response){ 

       var cName = $(response).find("fragment cName"); 
       var cind = $(response).find("fragment cName").attr("cind"); 

       $('#slider-name .slider-copy').html(cName); 
       $('#slider-indu .slider-copy').html(cind); 
       }); 


     }); 
}); 

,当然它不能在IE浏览器正常工作。事实上,没有任何负载。

示例XML文档:

<fragment> 
    <cName cind="Industrial" stat="Active">ABC Company</cName> 
    <hq>Chicago, IL</hq> 
</fragment> 

我发现了一些奇怪的事情,当我删除此行:

var cName = $(response).find("fragment cName");

它工作正常。出于某种原因,我可以获得XML节点的属性,但不是实际的节点?任何帮助,将不胜感激...

+0

尝试使用$ .ajax而不是$ .get并将dataType更改为xml – 2010-06-22 16:50:49

回答

1

你所确定的行:

var cName = $(response).find("fragment cName"); 

jQuery对象赋值给变量cName,而不是它的文本内容,它看起来像你想要的。尝试更改为

var cName = $(response).find("fragment cName").text(); 
+0

Genious。这工作。谢谢! – 2010-06-22 17:08:40

1

jQuery should not be used to parse XML

而应该指定XmlHttpRequestdataType来告诉浏览器解析XML,在回调后添加, 'xml'
response将成为一个XML DOM树,您可以使用jQuery进行遍历。

例如:

$.get(this.href, function(response){ 

    var cName = $(response).find("fragment cName"); 
    //... 
    }, "xml"); 
+0

我试过这个解决方案;它似乎没有工作.. – 2010-06-22 16:55:38

+0

为什么不呢?发生了什么? 'response'的价值是什么? – SLaks 2010-06-22 17:03:50