holdanddeepdive/javascript-deep-dive

43장 Ajax

Opened this issue · 0 comments

const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://jsonplaceholder.typicode.com/todos/1');
xhr.send();
xhr.onload = () => {
    // HTTP 요청이 성공적으로 완료된 경우에만 발생
    if (xhr.status === 200){
        console.log(JSON.parse(xhr.response));
    } else {
        console.log('Error', xhr.status, xhr.statusText);
    }
}