index.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<form action="http://localhost:8045/list" method="get">
<input type="text" name="name" />
<input type="text" name="age" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
server.js文件
/*
接收get数据
*/
const http = require('http');
const querystring = require('querystring');//解析带&符的字符串
const url_ = require('url');//专门解析url的
http.createServer(function(req,res){
console.log(req.url);
let url = req.url.indexOf('?') != -1 ? req.url.split('?')[1] : '';
let json = querystring.parse(url);
let json1 = req.url.indexOf('?') != -1 ? url_.parse(req.url,true) : '';//第二个参数是指是否要把query解析成json
console.log(json);
console.log(json1);
res.write('aaa');
res.end();
}).listen(8045);