1019--Node登录示例
程序员文章站
2022-03-03 17:41:06
...
Node
前端:提交登录
后端:接收,并处理。
//----------
//前端:loginTest.html
//----------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录与注册</title>
</head>
<body>
<form action="http://localhost:3000/login">
userName:<input type="text" name="userName"><br/>
passWord:<input type="password" name="passWord"><br/>
<input type="submit" value="登录">
</form>
</body>
</html>
//----------
//后端:router.js
//----------
var http = require("http");
var url = require("url");
httpServer= http.createServer(
function (req,res) {
//拦截广告
if(url.parse(req.url).pathname=='/favicon.ico')
return;
console.log("0--------------");
res.writeHead(200,
{"content-type":"text/html;charset=UTF-8"}
);
var urlString= req.url;
var url02=url.parse(urlString,true);//string-->对象
// console.log(url02);
if (url02.pathname==="/login"){
res.write("userName:"+ url02.query.userName);
}
if (url02.pathname=="/register"){
res.write("user register 2:"+ url02.query.userName);
}
res.end();
console.log("2------xx------")
}
).listen(3000,"localhost");