jQuery,XML as String和IE [英] jQuery, XML as a String, and IE

查看:79
本文介绍了jQuery,XML as String和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚继承了一个主导航菜单目前是Flash的项目。他们问我是否可以将其切换为javascript,所以我同意试一试。导航结构本身在服务器上动态生成,并通过ajax调用选择新节点。返回是所有XML。

I just inherited a project where the main navigation menu is currently Flash. They asked if I could switch it to javascript, so I agreed to give it a shot. The navigation structure itself is dynamically generated on the server and new nodes are picked via an ajax call. The return is all XML.

为防止初始加载延迟,服务器将xml从当前页面的第一次调用发送到textarea。

To prevent delays on initial load, the server sends down the xml from a first call for the current page into a textarea.

Firefox和Chrome可以拉动xml并在jQuery中操作它就好了。然而,IE扼杀了。我知道如果没有设置MIME类型IE浏览器效果不好,但由于服务器基本上没有限制,我需要找到解决方法。

Firefox and Chrome can pull that xml and manipulate it in jQuery just fine. IE, however, chokes out. I know that IE doesn't play well if the MIME type isn't set, but as the server is essentially off limits, I need to find a way around this.

存储在textarea中的xml示例如下:

An example of the xml stored in the textarea would be something like:


< nav>
< item name ='Link 1'url ='http://www.somesite.com'img ='/ path / to / image.png'/>
< item name ='Link 2'url ='http://www.somesite.com'img ='/ path / to / image.png'/>
< / nav>

我使用.val()方法抓取内容,该方法适用于IE以外的所有方法。我已经把头撞了一会儿。有什么帮助?

I am grabbing the contents using the .val() method, which works in everything other than IE. I have banged my head for awhile on this. Any help?

推荐答案

此问题已得到解决这里

<script type="text/javascript">

$(parseXml($("#xml").val())).find('item').each(function(){
 ...

});

function parseXml(xml)
{
    if (jQuery.browser.msie)
    {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.loadXML(xml);
        xml = xmlDoc;
    }
    return xml;
}

</script>

这篇关于jQuery,XML as String和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆