热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在IE6中使用jQuery解析XML-IssuesparsingXMLwithjQueryinIE6

ImtryingtoextractvaluesfromxmlusingjQueryinacross-browsercompatiblefashion.Imnotha

I'm trying to extract values from xml using jQuery in a cross-browser compatible fashion. I'm not having any issues doing this in firefox, but unfortunately this also has to be IE compatible.

我试图用跨浏览器兼容的方式使用jQuery从xml中提取值。在firefox中我没有遇到任何问题,但不幸的是,这也必须与IE兼容。

My jQuery code looks like this:

我的jQuery代码是这样的:

$(document).ready(function()) {
  $.get("file.xml", {}, function(parseRefreshTime){
    alert('This line is executed in IE.');  
    $("created", parseRefreshTime).each(function() {
      alert('This line is *not* executed in IE.');  
      refreshTime = $(this).text();
      //do stuff with refreshtime
    });
  });
});

This extracts the node value for a node in my xml file.

这将提取xml文件中 <创建的> 节点的节点值。

I'm referencing the jQuery library in my page, and it's parsing properly in Firefox, so I'm assuming that that my parsing code is appropriate. I get both alerts in Firefox, but only the first one in IE.

我在我的页面中引用了jQuery库,它在Firefox中正确解析,所以我假设我的解析代码是合适的。我在Firefox中收到了这两个警告,但只有IE中的第一个。

I could swear I had very similar code working yesterday, but I must have tweaked something and somehow broken it. After fighting with it for almost an hour now, I'm looking for another set of eyes.

我可以发誓昨天我有非常相似的代码,但我一定是修改了一些东西,并以某种方式破坏了它。在与它搏斗了近一个小时之后,我正在寻找另一副眼睛。

Can anyone spot what I'm doing wrong here?

有人能看出我在这里做错了什么吗?

5 个解决方案

#1


4  

A few things:

几件事:

  • Specify the response type as xml for your AJAX request
  • 为AJAX请求指定响应类型为xml
  • Wrap the returning XML object in $(doc) and use find to query the XML
  • 将返回的XML对象包装为$(doc)并使用find查询XML
  • I think you have a few typos in your first line: reader should be ready and you have an extra closing parentheses
  • 我认为你的第一行有一些拼写错误:读者应该准备好了,你还有一个额外的圆括号

This is working for me on IE6. If this doesn't work for you, you may want to look into whether you are serving up your xml properly.

这是我在IE6上的成果。如果这对您不起作用,您可能需要检查是否正确地提供了xml。

index.html:

index . html:




  
  

   
  





test.xml:

test.xml:


2010-01-07 00:00:00

#2


2  

try to wrap parseRefreshTime with $()

尝试使用$()包装parseRefreshTime

    $("created", $(parseRefreshTime)).each(function() {
      alert('This line is *not* executed in IE.');  
      refreshTime = $(this).text();
      //do stuff with refreshtime
    });

or try to use $(parseRefreshTime).find('created')

或者尝试使用$(parseRefreshTime).find('created')

    $(parseRefreshTime).find("created").each(function() {
      alert('This line is *not* executed in IE.');  
      refreshTime = $(this).text();
      //do stuff with refreshtime
    });

updated: also, try you specify the type to xml.

更新:另外,尝试将类型指定为xml。

$.get("file.xml", {}, , "xml")

#3


1  

Make sure that 'text/xml' is used as the content-type for the xml file.

请确保将“text/xml”用作xml文件的内容类型。

#4


0  

I am using something like this:

我用的是这样的东西:

    if ($.browser.msie){
        var tempXML = new ActiveXObject("Microsoft.XMLDOM");
        tempXML.async = false;
        tempXML.loadXML(data);
        xmlc = tempXML;
        items = $($(xmlc)[0]);
    } else if(window.DOMParser){
        items = $(new DOMParser().parseFromString(data, "text/xml").childNodes[0]);
    } else {
        xmlc = data;
        items = $($(xmlc)[1]);
    }

Basically, try the Microsoft.XMLDOM way for IE. can you provide sample xml?

基本上,微软尝试。XMLDOM IE。能否提供示例xml?

#5


0  

One of the biggest cave-eats with XML and IE6 is character encoding. Make sure your browser can interpret the file correctly. It could very well be your webserver is serving the page with a different encoding header in comparison to the document itself.

XML和IE6最大的难题之一是字符编码。确保浏览器能够正确地解释文件。与文档本身相比,您的webserver很可能使用不同的编码头来服务页面。


推荐阅读
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 解决nginx启动报错epoll_wait() reported that client prematurely closed connection的方法
    本文介绍了解决nginx启动报错epoll_wait() reported that client prematurely closed connection的方法,包括检查location配置是否正确、pass_proxy是否需要加“/”等。同时,还介绍了修改nginx的error.log日志级别为debug,以便查看详细日志信息。 ... [详细]
  • Introduction(简介)Forbeingapowerfulobject-orientedprogramminglanguage,Cisuseda ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • t-io 2.0.0发布-法网天眼第一版的回顾和更新说明
    本文回顾了t-io 1.x版本的工程结构和性能数据,并介绍了t-io在码云上的成绩和用户反馈。同时,还提到了@openSeLi同学发布的t-io 30W长连接并发压力测试报告。最后,详细介绍了t-io 2.0.0版本的更新内容,包括更简洁的使用方式和内置的httpsession功能。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • WebSocket与Socket.io的理解
    WebSocketprotocol是HTML5一种新的协议。它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • Servlet多用户登录时HttpSession会话信息覆盖问题的解决方案
    本文讨论了在Servlet多用户登录时可能出现的HttpSession会话信息覆盖问题,并提供了解决方案。通过分析JSESSIONID的作用机制和编码方式,我们可以得出每个HttpSession对象都是通过客户端发送的唯一JSESSIONID来识别的,因此无需担心会话信息被覆盖的问题。需要注意的是,本文讨论的是多个客户端级别上的多用户登录,而非同一个浏览器级别上的多用户登录。 ... [详细]
author-avatar
西红柿
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有