node.js express中get

var express = require('express');
var app = express();
app.use(express.static('public'));
console.log(__dirname);
app.get('/get.html', function (req, res) {
   res.sendFile( __dirname + "/" + "get.html" );
})
app.get('/process_get', function (req, res) {
   // 输出 JSON 格式
   response = {
       first_name:req.query.first_name,
       last_name:req.query.last_name
   };
   console.log(response);
   //var aaa = JSON.parse(response);
   console.log(response.last_name);
   res.end(JSON.stringify(response));
})
var server = app.listen(8081, function () {
  var host = server.address().address
  var port = server.address().port
  console.log("应用实例,访问地址为 http://%s:%s", host, port)

})

get.html

<html>
<body>
<form action="http://10.77.50.111:8081/process_get" method="GET">
First Name: <input type="text" name="first_name">  <br>
Last Name: <input type="text" name="last_name">
<input type="submit" value="Submit">
</form>
</body>
</html>

    A+
发布日期:2016年08月01日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: