开发者

$.get code not working in IE (JQuery)

I have this code, loading XML documents on mouseenter, which works in 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("c开发者_Go百科ind");

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


         });
});

and OF COURSE it doesn't work correctly in IE. In fact, nothing loads.

Sample XML document:

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

I found something strange, when I remove this line:

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

it works fine. For some reason, I can get the attribute of the XML nodes, but not the actual nodes? Any help would be appreciated...


The line you identified:

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

assigns the jQuery object to the variable cName, not it's text content which it looks like you want. Try changing it to

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


jQuery should not be used to parse XML.

Instead, you should specify the dataType of the XmlHttpRequest to tell the browser to parse the XML, by adding , 'xml' after the callback.
response will then be an XML DOM tree, which you can traverse using jQuery.

For example:

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜