$ .parseXML无法使用有效的xml [英] $.parseXML not working with valid xml

查看:172
本文介绍了$ .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报告为有效,不会引发错误。我知道我可以使用$(响应),但我不需要。

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

推荐答案


dataType

默认值:Intelligent Guess(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.

结果应该已经被解析。

如果你特别不希望它被解析,请使用不同的 dataType

If you specifically don't want it to be parsed, use a different dataType.

这篇关于$ .parseXML无法使用有效的xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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