ajax 获取服务器返回的XML字符串
前台
解析失败不会抛出任何异常, 只会返回一个给定的错误文档
let l = console.log
let http = ajanuw.create({
uri: 'http://localhost:1995/api',
timeout: 3000
});
http.request('get', '/xml', {
name: 'xml',
query: {
data: 1
},
resType: 'text'
})
.then(res => {
let data = res.data
// l(data)
// let dataview = new DataView(data)
// var ints = new Int32Array(data.byteLength / 4);
// for (var i = 0; i < ints.length; i++) {
// ints[i] = dataview.getInt32(i * 4);
// }
var parser = new DOMParser();
var doc = parser.parseFromString(data, 'application/xml');
l(doc)
})
http.request('get', '/xml', {
name: 'xml',
query: {
data: 1
},
resType: 'document'
})
.then(res => {
let data = res.data
l(data)
})
后台
@Get('xml')
@Header('access-control-allow-origiN', '*')
xml(@Query() query): Observable < string > {
l(query)
let data = bindNodeCallback(fs.readFile)(path.resolve(__dirname, './', 'test.xml')).pipe(map(v => v.toString('utf8')))
return data
}