$.parseXML 不适用于有效的 xml [英] $.parseXML not working with valid xml

查看:25
本文介绍了$.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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