問題描述
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!