admin管理员组文章数量:1417064
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.
To prevent delays on initial load, the server sends down the xml from a first call for the current page into a textarea.
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.
An example of the xml stored in the textarea would be something like:
<nav>
<item name='Link 1' url='' img='/path/to/image.png' />
<item name='Link 2' url='' img='/path/to/image.png' />
</nav>
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?
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.
To prevent delays on initial load, the server sends down the xml from a first call for the current page into a textarea.
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.
An example of the xml stored in the textarea would be something like:
<nav>
<item name='Link 1' url='http://www.somesite.' img='/path/to/image.png' />
<item name='Link 2' url='http://www.somesite.' img='/path/to/image.png' />
</nav>
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?
Share Improve this question asked Feb 17, 2010 at 18:21 Kevin EatonKevin Eaton 1103 silver badges13 bronze badges 1- I should mention that I am taking the XML, iterating over the elements and any children, and then creating <ul>'s with the elements and adding it to the menu where necessary. It works great in everything other than IE and I need to get a IE workaround ASAP. Thanks again! – Kevin Eaton Commented Feb 17, 2010 at 18:32
3 Answers
Reset to default 5This issue has been resolved here
<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>
I don't know that using Javascript is a good idea in order to implement this. If anything, I would implement this as a series of nested UL/LI elements (with links inside the LI elements) and then use a third-party library like jQuery to generate the menu for you (there are a number of plugins which will create menus for you based on this structure (or a similar hierarchical structure).
This leads to better searchability on your site, since search engines won't process the ajax call to get the content, and this way, your links are embedded in the page.
Also, it requires less code on your part, since most libraries like jQuery correctly abstract out the differences in browsers when offering their functionality.
A suggestion would be to make sure you set the content type in your ajax call to "xml".
datatype: "xml"
IE need this to be specifically spelled out.
I would also suggestion using json instead of XML due to the size overhead of XML. If this is an option for you I would seriously consider it. Json is very easy to work with and is extremely fast for ajax calls.
本文标签: JavaScriptJQueryXML as a Stringand IEStack Overflow
版权声明:本文标题:javascript - jQuery, XML as a String, and IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745260648a2650341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论