【发布时间】:2018-09-11 09:57:29
【问题描述】:
无法弄清楚如何从具有 XML 内容的 api 获取数据。我尝试使用 axios,使用 JSON 一切都很清楚。 我希望在加载时从 api 获取数据,并在表单字段中填写相应的值。
【问题讨论】:
无法弄清楚如何从具有 XML 内容的 api 获取数据。我尝试使用 axios,使用 JSON 一切都很清楚。 我希望在加载时从 api 获取数据,并在表单字段中填写相应的值。
【问题讨论】:
fetch(URL).then((results) => {
// results returns XML. Cast this to a string, then create
// a new DOM object out of it! like this
results
.text()
.then(( str ) => {
let responseDoc = new DOMParser().parseFromString(str, 'application/xml');
}
});
你也可以使用NPM module 来解析XML。
【讨论】: