Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
368 changes: 184 additions & 184 deletions 5-network/08-xmlhttprequest/article.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 5-network/08-xmlhttprequest/example.view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
}
</script>

<button onclick="run()">Load digits</button>
<button onclick="run()">숫자 불러오기</button>

<ul id="log"></ul>
2 changes: 1 addition & 1 deletion 5-network/08-xmlhttprequest/hello.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello from the server!
서버에서 보낸 인사입니다!
10 changes: 5 additions & 5 deletions 5-network/08-xmlhttprequest/phones-async.view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>

<button onclick="loadPhones()" id="button">Load phones.json!</button>
<button onclick="loadPhones()" id="button">phones.json 불러오기!</button>

<script>
function loadPhones() {
Expand All @@ -21,19 +21,19 @@
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;

button.innerHTML = 'Complete!';
button.innerHTML = '완료!';

if (xhr.status != 200) {
// handle error
// 에러 처리
alert(xhr.status + ': ' + xhr.statusText);
} else {
// show result
// 결과 표시
alert(xhr.responseText);
}

}

button.innerHTML = 'Loading...';
button.innerHTML = '로딩 중...';
button.disabled = true;
}
</script>
Expand Down
8 changes: 4 additions & 4 deletions 5-network/08-xmlhttprequest/phones.view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>

<button onclick="loadPhones()">Load phones.json!</button>
<button onclick="loadPhones()">phones.json 불러오기!</button>

<script>
function loadPhones() {
Expand All @@ -15,10 +15,10 @@
xhr.send();

if (xhr.status != 200) {
// handle error
alert('Error ' + xhr.status + ': ' + xhr.statusText);
// 에러 처리
alert('에러 ' + xhr.status + ': ' + xhr.statusText);
} else {
// show result
// 결과 표시
alert(xhr.responseText);
}
}
Expand Down
2 changes: 1 addition & 1 deletion 5-network/08-xmlhttprequest/phones.view/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let file = new static.Server('.', {
function accept(req, res) {

if (req.url == '/phones.json') {
// stall a bit to let "loading" message show up
// "로딩 중" 메시지가 보이도록 잠시 지연
setTimeout(function() {
file.serve(req, res);
}, 2000);
Expand Down
4 changes: 2 additions & 2 deletions 5-network/08-xmlhttprequest/post.view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
const chunk = await reader.read();

if (chunk.done) {
console.log("done!");
console.log("완료!");
break;
}

chunks.push(chunk.value);
receivedLength += chunk.value.length;
console.log(`${receivedLength}/${contentLength} received`)
console.log(`${receivedLength}/${contentLength} 수신`)
}


Expand Down
10 changes: 5 additions & 5 deletions 5-network/08-xmlhttprequest/post.view/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function accept(req, res) {
chunks.push(data);
length += data.length;

// More than 10mb, kill the connection!
// 10mb를 넘으면 연결을 종료합니다!
if (length > 1e8) {
req.connection.destroy();
}
Expand All @@ -28,16 +28,16 @@ function accept(req, res) {

if (req.url == '/user') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'User saved' }));
res.end(JSON.stringify({ message: '사용자 정보 저장 성공' }));
} else if (req.url == '/image') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: "Image saved", imageSize: length }));
res.end(JSON.stringify({ message: "이미지 저장 성공", imageSize: length }));
} else if (req.url == '/upload') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: "Upload complete", size: length }));
res.end(JSON.stringify({ message: "업로드 완료", size: length }));
} else {
res.writeHead(404);
res.end("Not found");
res.end("찾을 수 없음");
}
});

Expand Down