我的xml看起来像这样:
<batch>
<status>true</status>
<sub_batch>
<batchNO>TEST1</batchNO>
<batchExpiry>TEST1</batchExpiry>
<batchQty>51</batchQty>
</sub_batch>
<sub_batch>
<batchNO>TEST2</batchNO>
<batchExpiry>TEST2</batchExpiry>
<batchQty>52</batchQty>
</sub_batch>
<sub_batch>
<batchNO>TEST3</batchNO>
<batchExpiry>TEST3</batchExpiry>
<batchQty>53</batchQty>
</sub_batch>
</batch>
我的jquery看起来像这样:
$.ajax({
type: "GET",
url: "../inventory_ajax/di_get_batch.jsp?dinvid="+prd_di_inv_id,
dataType: "xml",
async: false,
success: function(xml){
$('sub_batch', xml).each(function(){
var value = $(this).attr('value');
var label = $(this).text();
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
如何通过获取每个sub_batch及其内容的值来实现它的工作,如batchNo / batchExpiry / batchQTY
感谢
答案 0 :(得分:1)
尝试,
$('sub_batch',xml).each(function () {
$(this).children().each(function () {
alert($(this).prop('tagName') + ":" + $(this).text());
})
});