express,使用get方法和post方法

版权声明:Null https://blog.csdn.net/yudiyanwang/article/details/73412274
/**
 * Created by os on 17-6-18.
 */

var express = require('express')
// var http = require('http')
var fs = require('fs')
var app = express()

app.get('/index.html',function(req,res){
    res.sendfile(__dirname+'/index.html')
    // res.send('hello world')
})

app.post('/index.html',function(req,res){
    req.on('data',function(data){
        var obj = data.toString()
        console.log(obj)
        res.send(data.toString())
    })
})
app.listen(8889,'127.0.0.1')
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
山丘
<form action="index.html" method="post">
    <input type="text" name="username" placeholder="请输入姓名"><br>
    <input type="text" name="age" placeholder="请输入年龄"><br>
    <input type="submit" value="提交">
</form>
</body>
</html>
阅读更多
想对作者说点什么?
相关热词

博主推荐

换一批

没有更多推荐了,返回首页