通过 Ajax 发送请求后,我得到了以下 xml 响应,因此我想使用jQuery解析以下xml数据以获取特定的属性值。
<Room1>
<Node Name='Scene1' Text='Morning'/>
<Node Name='Scene2' Text='Leaving'/>
<Node Name='Scene3' Text='Morning'/>
<Node Name='Scene4' Text='Entertainment'/>
<Node Name='Scene5' Text='Party'/>
<Node Name='Scene6' Text='s6'/>
<Node Name='Scene7' Text='Watch TV'/>
<Node Name='Scene8' Text='Watch Movie'/>
<Node Name='Scene9' Text='TV on Screen'/>
<Node Name='Scene10' Text='Movie on Screen'/>
<Node Name='Scene11' Text='Leaving Room'/>
</Room1>
我想获取属性Name和Text的值。以下代码是我尝试过的,
$.ajax({
method : "GET",
url : "controller/Controller.php",
data : "myData=Room1",
success:function(response){
var xml = response;
$(xml).find('Room1').each(function(){
$(this).find('Node').each(function(){
console.log($(this).attr('Name'));
});
});
}
});
提前致谢