2021 프론트 엔드 로드맵 따라가기/JS
AJAX POST request
알 수 없는 사용자
2021. 6. 7. 22:34
Content-Type 헤더를 지정해주는 것과 보낼 데이터를 JSON 문자열로 변경하여 보내야 하는 점에 주의하자.
// Make an Http POST Request
EasyHttp.prototype.post = function (url, data, callback) {
this.http.open("POST", url, true);
this.http.setRequestHeader("Content-type", "application/json");
let self = this;
this.http.onload = function () {
callback(null, self.http.responseText);
}
this.http.send(JSON.stringify(data));
};