Ajax는 불필요한 리소스 전달을 최소화하여,
클라이언트 및 서버 간의 작업 속도를 최소화시켜주는 기술 중 하나이다.
수 많은 방법이 있겠지만, 이번에는 Fetch API를 사용하여 구현을 해 보았다.
//보내고자 하는 메시지의 형태
var message = {
username: 'sangwookim',
text: 'hello!',
roomname: 'IM13'
};
const serverURL = 'http://52.78.213.9:3000/messages' //연결하여 사용할 서버 url
window.fetch(serverURL, {
method: 'POST',
body: JSON.stringify(message),
headers: {
"Content-Type": "application/json",
}
}).then(response => {
return response.json();
}).then(json => {
console.log(json);
// message sent!
});
| checkpoints 12 - module exports, setTimeOut, event loop (0) | 2019.06.19 |
|---|---|
| Solo Sprint - Servers and Node (0) | 2019.06.18 |
| Subclassing in ES6 - Javascript (0) | 2019.06.09 |
| 이머시브 2주차 5일 - Intro Web Architecture (0) | 2019.06.08 |
| Inheritance Pattern - Javascript (0) | 2019.06.04 |
댓글 영역