[GET 방식]
var xhr = new XMLHttpRequest();
xhr.open("GET", "your_url", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// success code here
}
};
xhr.send();
[POST 방식]
var xhr = new XMLHttpRequest();
xhr.open("POST", "your_url", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// success code here
}
};
xhr.send(JSON.stringify({data: "your_data"}));
출처 : GPT
'프로그래밍 > Javascript' 카테고리의 다른 글
[Javascript] 프로토타입 이란 (0) | 2023.02.12 |
---|---|
[Javascript] 프로퍼티 란? (0) | 2023.02.11 |
[Javascript] 얕은 복사, 깊은 복사 (1) | 2022.09.19 |
[Javascript] 페이지 갱신없이 주소URL 변경하기 (0) | 2022.03.28 |
[Javascript]ajax에 대해서 (0) | 2022.03.06 |