我正在使用Google API和javascript,当我打电话时,我从API得到2条响应。有没有一种方法可以将响应限制为首次拨打电话?
const Http = new XMLHttpRequest();
const url = "API_LINK_TO_CALL"
;
Http.open("GET", url);
Http.send();
Http.onreadystatechange=(e)=>{
result = JSON.parse(Http.responseText);
console.log(result);
}
答案 0 :(得分:0)
等待响应准备就绪
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
Http.onreadystatechange = function() {
if (Http.readyState == XMLHttpRequest.DONE) {
const result = JSON.parse(Http.responseText);
console.log(result);
}
}