Skip to Content
網頁應用程式設計--使用 Node 和 Express
book

網頁應用程式設計--使用 Node 和 Express

by Ethan Brown
December 2014
Intermediate to advanced
336 pages
6h 34m
Chinese
GoTop Information, Inc.
Content preview from 網頁應用程式設計--使用 Node 和 Express
請求與回應物件
|
57
式與查詢字串一樣)。如果
POST
需要支援檔案上傳,媒體類型是
multipart/form-data
這是比較複雜的格式。最後,AJAX 請求的內文可以使用
application/json
參數
“參數”這個字可代表許多東西,通常也是會令人疑惑的地方。對於所有的請求,參數
可能是查詢字串、期程(需要 cookie,見第九章)、請求內文,或具備名稱的路由參數
(我們會在第十四章進一步學習)。在 Node 應用程式中,請求物件的
param
方法會自行
轉換這所有的參數。因此,我建議你不要使用它。這通常會產生問題:如果有一個參數
被設為查詢字串某個東西,以及另一個在
POST
內文或期程中的東西時,哪一個值勝出?
它會造成令人抓狂的錯誤。PHP 是造成這種麻煩的主要原因:為了“方便”起見,它會
自行將所有字串轉換成一個名為
$_REQUEST
的變數,而且因為某些原因,大家都認為這
是一種很好的做法。我們將會看到負責保存各種參數類型的專用特性,我認為這是比較
不會造成困擾的方式。
請求物件
請求物件(通常會被傳遞至回呼,代表你可以視需要為它命名,它通常被命名為
req
request
)一開始是
http.IncomingMessage
的實例,Node 的核心物件。Express 加入額外
的功能。我們來看請求物件最好用的特性及方法(這些方法都是 Express 添加的,除了
req.headers
req.url
之外,它們來自 Node):
req.params
含有
具有名稱的路由參數
的陣列。我們會在第十四章進一步討論。 ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5與JAVASCRIPT WEB APPS開發實務

HTML5與JAVASCRIPT WEB APPS開發實務

Wesley Hales
jQuery Mobile建置與執行

jQuery Mobile建置與執行

Maximiliano Firtman

Publisher Resources

ISBN: 9789863474371