XMLHttpRequest를 이용 test.html의 데이터 받아오기 (Nodejs에서 쓰려면 npm으로 설치해야 한다.)
let request = new XMLHttpRequest();
request.open('GET', 'test.html');
console.log(request.responseText);
request.send();
Fetch API를 이용해 test.html의 데이터 받아오기
fetch('test.html') //명시하지 않으면 GET방식으로 통신한다
.then(function(response) {
console.log(response.text());
})
XMLHttpRequest 참조 : https://developer.mozilla.org/ko/docs/Web/API/XMLHttpRequest
XMLHttpRequest 레퍼런스 : https://xhr.spec.whatwg.org/
XMLHttpRequest
XMLHttpRequest 는 그 이름으로봐서 XML 만 받아올 수 있을 것 같아 보이지만, 모든 종류의 데이터를 받아오는데 사용할 수 있습니다. 또한 HTTP 이외의 프로토콜도 지원합니다(file 과 ftp 포함).
developer.mozilla.org
XMLHttpRequest Standard
Abstract The XMLHttpRequest Standard defines an API that provides scripted client functionality for transferring data between a client and a server. Table of Contents 1 Introduction 1.1 Specification history 2 Conformance 2.1 Extensibility 3 Terminology 4
xhr.spec.whatwg.org
Fetch API 참조 : https://developer.mozilla.org/ko/docs/Web/API/Fetch_API
Fetch API 레퍼런스 : https://fetch.spec.whatwg.org/
Fetch API
Fetch API는 네트워크 통신을 포함한 리소스 취득을 위한 인터페이스가 정의되어 있습니다. XMLHttpRequest와 같은 비슷한 API가 존재합니다만, 새로운 Fetch API는 좀더 강력하고 유연한 조작이 가능합니다.
developer.mozilla.org
Fetch Standard
fetch.spec.whatwg.org