IE8 中的 jQuery XML 解析
我有一些正在 jQuery 中解析的 XML。
<payload>
<value key="VehicleMake">
<value key="description">Aeon</value>
<value key="code">18</value>
</value>
<value key="VehicleMake">
<value key="description">Alfa Romeo</value>
<value key="code">120</value>
</value>
</payload>
在除 IE(特别是 IE8)之外的所有浏览器中,以下工作有效:
$.ajax({
type : "GET",
async : false,
url : "/services/vehiclemake",
success :
function(xmlResponse) {
var data = $("payload", xmlResponse).children("value").map(function() {
//IE8 fails on the next line
var code = $(this).children("value [key='code']").text();
var desc = $(this).children("value [key='description']").text();
return {
value : desc,
vehicleCode : code,
label : desc
};
}).get();
}
});
在 IE8 中,对“code”的赋值失败,提示:“TypeError:对象不支持此属性或方法”。
如果我使用这种方法那就没问题了:
$.ajax({
type : "GET",
async : false,
url : "/services/vehiclemake",
success :
function(xmlResponse) {
var data = $("payload", xmlResponse).children("value").map(function() {
var code;
var desc;
var elements = $(this).children();
for (i = 0; i < elements.length; i++) {
if(elements[i].attributes.getNamedItem("key").value == 'code') {
code = elements[i].text;
}
if(elements[i].attributes.getNamedItem("key").value == 'description') {
desc = elements[i].text;
}
}
var desc = $(this).children("value [key='description']").text();
return {
value : desc,
vehicleCode : code,
label : desc
};
}).get();
谁能告诉我为什么标准 jQuery 属性选择器在 IE8 中不起作用? XML 将以正确的 mime 类型返回。
谢谢。
I have some XML that I am parsing in jQuery.
<payload>
<value key="VehicleMake">
<value key="description">Aeon</value>
<value key="code">18</value>
</value>
<value key="VehicleMake">
<value key="description">Alfa Romeo</value>
<value key="code">120</value>
</value>
</payload>
In all browsers except IE (specifically IE8) the following works:
$.ajax({
type : "GET",
async : false,
url : "/services/vehiclemake",
success :
function(xmlResponse) {
var data = $("payload", xmlResponse).children("value").map(function() {
//IE8 fails on the next line
var code = $(this).children("value [key='code']").text();
var desc = $(this).children("value [key='description']").text();
return {
value : desc,
vehicleCode : code,
label : desc
};
}).get();
}
});
In IE8 it fails on the assignment to 'code' saying : "TypeError: Object doesn't support this property or method".
If I use this approach then it is fine:
$.ajax({
type : "GET",
async : false,
url : "/services/vehiclemake",
success :
function(xmlResponse) {
var data = $("payload", xmlResponse).children("value").map(function() {
var code;
var desc;
var elements = $(this).children();
for (i = 0; i < elements.length; i++) {
if(elements[i].attributes.getNamedItem("key").value == 'code') {
code = elements[i].text;
}
if(elements[i].attributes.getNamedItem("key").value == 'description') {
desc = elements[i].text;
}
}
var desc = $(this).children("value [key='description']").text();
return {
value : desc,
vehicleCode : code,
label : desc
};
}).get();
Can anyone tell me why the standard jQuery attribute selectors are not working in IE8? The XML is being returned with the correct mime type.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为你想要在这里留出空间:
可能无法解决它,但我认为无论如何都需要修复。
I don't think you want a space here:
Might not solve it but I think that needs fixing anyway.