スポンサーリンク

WindowsでExpress4(JavascriptのWEBフレームワーク)(5)

前回

http://twosquirrel.mints.ne.jp/?p=10333

に引き続き、

http://libro.tuyano.com/index3?id=1162003

をやってみる。

「クエリ―文字列の処理」
「フォームの送信処理」
「AjaxによるJSONデータ送受」
「クッキーの読み書き」

(環境)
Windows8.1
node.js v6.3.1
Visual Studio Code
templateはejs
C:/js/expressapp フォルダに作成

(1)クエリ―文字列によるパラメータ送信

クエリー???

http://libro.tuyano.com/index3?id=1162003 によると、

例えば、/index?a=helloであれば、quey.aに”hello”が保管されている

らしい。

routes/helo.js の変更

image

views/helo.ejs の変更

image

node .\bin\www

http://localhost:3000/helo

image

image

git add .
git commit -m “query”
git push -u origin –all

(2)フォームの送信について

http://libro.tuyano.com/index3?id=1162003&page=2

の通りにやってみる。

routes/helo.js の変更

image

views/helo.ejs の変更

image

node .\bin\www

http://localhost:3000/helo

image

image

あれ? アドレスをみると、 localhost:3000/form になっているので、helo.ejs を以下のように訂正。

(訂正前)
image

(変更後)
image

image

できた!

git add .
git commit -m “post”
git push -u origin –all

(3)Ajaxでアクセスした情報をJSONで受け取る

http://libro.tuyano.com/index3?id=1162003&page=3

をコピペ。

routes/helo.js の変更

image

views/helo.ejs の変更

なんだかすごく難しそう。。。

image

node .\bin\www

http://localhost:3000/helo

image

image

git add .
git commit -m “Ajax”
git push -u origin –all

(4)クッキーの利用

http://libro.tuyano.com/index3?id=1162003&page=4

の通りに、コピペ。

routes/helo.js の変更

image

views/helo.ejs の変更

image

node .\bin\www

http://localhost:3000/helo

image

image

git add .
git commit -m “cookie”
git push -u origin –all

次は、ラスト、以下をやってみたい!

Node.js/ExpressでPostgreSQLを使おう

作成:2013-07-06 09:44
更新:2013-07-06 09:44
http://libro.tuyano.com/index3?id=1194003

スポンサーリンク