$.parseXML not working with valid xml

删除回忆录丶 提交于 2019-12-06 21:44:29

问题


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
    }
});

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

回答1:


dataType
Default: Intelligent Guess (xml, json, script, or html)

"xml": Returns a XML document that can be processed via jQuery.

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.

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



来源:https://stackoverflow.com/questions/10147499/parsexml-not-working-with-valid-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!