$.parseXML not working with valid xml($.parseXML 不适用于有效的 xml)
问题描述
XML:
<?xml version="1.0"?>
<choices>
<choice>
<start>39</start>
<duration>6</duration>
<path>
<name></name>
<complete></complete>
</path>
<path>
<name></name>
<complete></complete>
</path>
</choice>
</choices>
$.ajax({
url: 'choices.xml',
context: this,
async: false,
success: function(response) {
var xmlDoc = $.parseXML(response);
console.log(xmlDoc); // null
}
});
XML 被报告为有效,并且没有引发错误.我知道我可以使用 $(response),但我不需要它.
The XML is reported as valid, and no error is thrown. I know I can use $(response), but I don't need that.
- jQuery 1.7.2
推荐答案
数据类型
默认值:智能猜测(xml、json、脚本或 html)
dataType
Default: Intelligent Guess (xml, json, script, or html)
xml":返回一个可以通过 jQuery 处理的 XML 文档.
"xml": Returns a XML document that can be processed via jQuery.
$.ajax() 函数依赖于服务器来提供有关检索数据的信息.如果服务器将返回数据报告为 XML,则可以使用普通的 XML 方法或 jQuery 的选择器来遍历结果.如果检测到其他类型,例如上例中的 HTML,则将数据视为文本.
The $.ajax() function relies on the server to provide information about the retrieved data. If the server reports the return data as XML, the result can be traversed using normal XML methods or jQuery's selectors. If another type is detected, such as HTML in the example above, the data is treated as text.
结果应该已经被解析了.
The result should already be parsed.
如果您特别不想对其进行解析,请使用不同的 dataType
.
If you specifically don't want it to be parsed, use a different dataType
.
这篇关于$.parseXML 不适用于有效的 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:$.parseXML 不适用于有效的 xml


- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01