nodejs querystring

DEMO

01.JS

const http=require('http');
const querystring=require('querystring');

http.createServer(function (req, res){
  var GET={};

  if(req.url.indexOf('?')!=-1){
    var arr=req.url.split('?');
    var url=arr[0];
    
    GET=querystring.parse(arr[1]);
  }else{
    var url=req.url;
  }


  console.log(url, GET);

  //req获取前台请求数据
  res.write('how are you ');
  res.end();
}).listen(3000);

FORM.HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form  action="http://localhost:3000/" method="get">
        用户名:<input type="test" name="user" value="111">
        <br>
        密码:<input type="text" name="password" value="1111">
        <br>
        <input type="submit" value="提交">


    </form>

</body>
</html>

 

效果:

 

 webstrom输出效果:

 

 

 

DEMO

输出结果:

 

const querystring=require('querystring');
var json=querystring.parse("user=blue&pass=123456&age=18");
console.log(json);



posted @ 2017-11-05 19:51  1点  阅读(152)  评论(0编辑  收藏  举报