fetch API
fetch('html').then(funtion() {})

fetch() : 클라이언트가 서버에 인자에 전달된 파일을 요청한다.
then() : 응답이 끝나면 이 메서드를 실행한다.
function response() {
console.log(success);
};
fetch('html').then(response);
console.log(one);
console.log(two);
위의 코드를 실행하면 console.log는 어떤 순서로 실행 될까?
// 결과
one
two
success
왜 response() 함수가 먼저 실행되지 않았을까?
ajax는 비동기(asynchronous) 통신이기 때문이다. 비동기 통신은 기다리지 않고 한 번에 여러가지 일을 수행할 수 있다.
Last updated
Was this helpful?