【发布时间】:2018-09-12 11:35:58
【问题描述】:
当xml 的格式如下图时,我很难检索它,我可以检索InventoryResponse 就好了,但是当试图让孩子a:Cost它不起作用时。我试图进行研究,但没有看到任何适用于我的情况的例子。获得成本的最简单方法是什么?
$.ajax({
type: 'POST',
url: 'php/test.php',
dataType:"xml",
data: {
search:'set',
},
success: function(data){
var xml = $(data).find('InventoryResponse').html() ;
var cost= $(data).find('a:Cost').html() ;
$('.display').html(cost) ;
}
})
test.php 文件返回 xml
<InventoryResponse>
<Inventories>
<a:Inventory>
<a:ID>
12345
</a:ID>
<a:Cost>
20.00
</a:Cost>
</a:Inventory>
</Inventories>
</InventoryResponse>
【问题讨论】:
标签: javascript php jquery ajax xml