我正在用AJAX做一个POST请求,当我收到回复时,如果我试图提醒它,我得到了这个:
[object XMLDocument]
这是我的代码:
$(document).ready(function(){
$("button").click(function(){
var inputreg = document.getElementById("reginput").value;
$.post("linkhere...",
{
RegistrationNumber: inputreg,
username: "myusername",
dataType: "xml"
},
function(data){
alert(data);
});
}); });
我正在尝试从xml中获取某个值,例如“描述”..
编辑: 以下是回复的一部分:
<vehicleData>
<ABICode>12345</ABICode>
<Description>lorem ipsum</Description></vehicleData>
答案 0 :(得分:1)
鉴于data
是XMLDocument
,您可以在其上使用DOM方法来导航和检索值。例如
let description = data.querySelector('Description').textContent
这是一个例子
// ignore this section, it's just setting up the XML document
//////////////////////////
const xml = `<vehicleData>
<ABICode>12345</ABICode>
<Description>lorem ipsum</Description></vehicleData>`
const parser = new DOMParser()
const data = parser.parseFromString(xml, 'text/xml')
//////////////////////////
console.info(data.querySelector('Description').textContent)
&#13;