为什么XP上的IE8无法使用JQuery从XML正确读取? [英] Why is IE8 on XP not properly reading from XML using JQuery?

查看:94
本文介绍了为什么XP上的IE8无法使用JQuery从XML正确读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在data.xml中提供此XML

Given this XML in data.xml

<?xml version="1.0" encoding="utf-8"?>
<data>
  <bar>100</bar>
</data>

我想使用test.html中的以下代码显示"bar"元素中的内容

I want to display the content from the "bar" element using the following code in test.html

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
  $.get('data.xml', function(xml) {
    var foo = $(xml).find('bar').text();
    document.write("<span>foo: [" + foo + "]</span>");
  });
</script>
</body>
</html>

基于Webkit的浏览器中的输出:

The output in webkit based browsers:

foo: [100]

XP上IE8中的输出:

The output in IE8 on XP:

foo: []

当IE8将元素解释为空字符串时,为什么Webkit浏览器正确读取元素的内容?

Why do webkit browsers read the element's content correctly while IE8 interprets it as an empty string?

推荐答案

这看起来几乎是相同的问题.一些亮点:

This looks to be very much the same problem. Some highlights:

如果您将message.xml设置为错误的mime类型,则Internet Explorer不会将其解析为XML."

您需要更改服务器以发送"text/xml"作为内容类型."

应归功于 Matthew Crumley .

,并通过jQuery 文档:
如果将$ .ajax dataType选项指定为" xml,请确保服务器发送的MIME类型为" text/xml的内容.发送错误的MIME类型将阻止jQuery正确管理返回的数据.响应"

And from jQuery documentation:
"if you specify the $.ajax dataType option to be "xml", make sure your server sends content with the "text/xml" MIME type. Sending the wrong MIME type will prohibit jQuery from correctly managing the data returned in the response"

"使用dataType参数将xml文件加载为文本,并在成功函数中解析返回的数据"

这篇关于为什么XP上的IE8无法使用JQuery从XML正确读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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