我想解析文件,但代碼中的值「名稱」始終有一個空字符串。我如何解析XML文件與jquery
我的XML:
<row>
<id>1</id>
<AnrufenZahl>64</AnrufenZahl>
<NameOperator>Ioan</NameOperator>
</row>
<row>
<id>2</id>
<AnrufenZahl>35</AnrufenZahl>
<NameOperator>Dian</NameOperator>
</row>
<row>
<id>3</id>
<AnrufenZahl>50</AnrufenZahl>
<NameOperator>Bob</NameOperator>
</row>
和我的JS文件 我不有,從 「警戒」 功能輸出。
$(document).ready(function() { // load xml file using jquery ajax
$.ajax({
type: "GET",
url: "m.xml",
dataType: "xml",
success: function(xml) {
// var output = '<ul>';
$(xml).find('row').each(function(){
$(this).find("NameOperator").each(function(){
var name = $(this).text();
alert(name);
});
});
}
});
});
爲什麼'name'發現了什麼?您的標籤是標籤搜索是在標籤名稱上作爲一個整體完成的,而不是一個子串匹配。 –
我犯了錯誤,很抱歉,但代碼仍然無法正常工作。與NameOperator也 – DibaToner
你可以試試'console.log(this);'就在行$'(this).find(「NameOperator」)。each(function(){'並看看你的輸出是什麼 –