我尝试以角度显示服务中xml httprequest的响应。但是它返回未定义的。我也尝试使用提取API。它返回相同的
getResponse() {
let response
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://www.api-endpoint.com/get/heros.html", true);
xhttp.send()
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
response = this.response
}
}
return response
}
getResponse(){
let url="https://www.api-endpoint.com/get/heros.html"
let response
fetch(url)
.then(res=>JSON.stringify(res))
.then(data=> response=data)
return response
}