아약스로 읽고 싶은 이미지가 많습니다. 각 이미지의 URL을 알고 있다면 어떻게 3 개의 이미지 아약스 요청을 동시에 만들 수 있습니까?동시에 여러 아약스 요청
이 하나 개의 이미지
var image_url = images[i];
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log(xhr.response, typeof xhr.response);
}
}
xhr.open('GET', image_url);
xhr.responseType = 'blob';
xhr.send();
3 가지 동시 요청을 제한해야하는 이유는 무엇입니까? –
을 사용하면 서버에 과부하가 걸리지 않습니다. – yomamma
[Promise.all] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)을 찾고 있습니다. 아래의 솔루션은 JQuery를 사용하지만 바닐라 JS – lux