node的Get表单提交
form.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="http://127.0.0.1:3000/" method="GET"> 姓名<input type="text" name="name"><br> 年龄<input type="text" name="age"><br> 性别<input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女<br> <input type="submit" value="提交"> </form> </body> </html>
04.js
var http = require("http");
var url = require("url");
var server = http.createServer(function(req,res){
var queryObj=url.parse(req.url,true).query;
var name=queryObj.name;
var age=queryObj.age;
var sex=queryObj.sex;
res.writeHead(200,{"Content-type":"text/html;charset=UTF-8"});
res.end("服务器收到表单提交"+name+age+sex);
});
server.listen(3000,"127.0.0.1");
效果: