赞
踩
<!--HTML页面:-->
<form method="post" action="/user/login">
用户:<input type="text" name="uname"> <br>
密码:<input type="text" name="upwd"> <br>
<input type="submit" >
</form>
//user.js路由: const express=require('express'); const pool=require('../pool.js'); var router=express.Router(); router.post('/login',(req,res)=>{ var obj=req.body; var $uname=obj.uname; if(!$uname){ res.send({code:401,msg:'uname required'}); return; } var $upwd=obj.upwd; if(!$upwd){ res.send({code:402,msg:'upwd required'}); return; } var sql='SELECT * FROM xz_user WHERE uname=? AND upwd=?'; pool.query(sql,[$uname,$upwd],(err,result)=>{ if(err) throw err; if(result.length>0){ res.send({code:200,msg:'login success'}); }else{ res.send({code:301,msg:'login error'}); } }); }); //路由器导出 module.exports=router;
var http = require('http'); //加载http模块
var server=http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('hello world');
res.end(); //结束输出流
});
server.listen(3000);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。