Skip to Main Content
한 권으로 끝내는 Node & Express: 웹사이트 구축을 위한 서버 사이드 자바스크립트
book

한 권으로 끝내는 Node & Express: 웹사이트 구축을 위한 서버 사이드 자바스크립트

by 한성용, 이선 브라운
April 2016
Beginner to intermediate content levelBeginner to intermediate
389 pages
9h 8m
Korean
Hanbit Media, Inc.
Content preview from 한 권으로 끝내는 Node & Express: 웹사이트 구축을 위한 서버 사이드 자바스크립트
101
6
-
요청과 응답 객체
예제 6-9 기본 폼 처리
//
body
-
parser
미들웨어를
먼저
링크해야
합니다.
app
.
post
('/
process
-
contact
',
function
(
req
,
res
){
console
.
log
('
Received contact from
'
+
req
.
body
.
name
+
'
<'
+
req
.
body
.
email
+
'>');
//
데이터베이스에
저장
....
res
.
redirect
(
303
,
'/
thank
-
you
');
});
예제 6-10 . 더 견고한 폼 처리
//
body
-
parser
미들웨어를
먼저
링크해야
합니다.
app
.
post
('/
process
-
contact
',
function
(
req
,
res
){
console
.
log
('
Received contact from
'
+
req
.
body
.
name
+
'
<'
+
req
.
body
.
email
+
'>');
try
{
//
데이터베이스에
저장
....
return res
.
xhr
?
res
.
render
({
success
:
true
})
:
res
.
redirect
(
303
,
'/
thank
-
you
');
}
catch
(
ex
)
{
return res
.
xhr
?
res
.
json
({
error
:
'
Database error
.'
})
:
res
.
redirect
(
303
,
'/
database
-
error ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

한 권으로 끝내는 Node & Express(2판): 모던 웹을 위한 서버 사이드 자바스크립트의 모든 것

한 권으로 끝내는 Node & Express(2판): 모던 웹을 위한 서버 사이드 자바스크립트의 모든 것

한선용, 이선 브라운

Publisher Resources

ISBN: 9788968482229