• Node.js系列02


    1.Node.js 中 moudle.exprots 的用法:

    如果暴露一个类, 就用module.exprots 。

     1 /**
     2  * Created by aytsoft on 2016/4/25.
     3  */
     4 /*如果是暴露一个类 就用moudle.exprots = 类名*/
     5 function Pepole(name, age){
     6     this.name = name;
     7     this.age = age;
     8 
     9 }
    10 Pepole.prototype = {
    11     constructor:Pepole,
    12     getMsg :function(){
    13         console.log(this.name + "  "+ this.age);
    14     }
    15 }
    16 module.exports = Pepole;

    2. querystring 的简单用法:

    post提交

     1 /**
     2  * Created by aytsoft on 2016/4/25.
     3  */
     4 var http  = require("http");
     5 var queryString = require("querystring");
     6 
     7 
     8 var server = http.createServer(function(req, res){
     9     if(req.url =="/favicon.ico"){
    10         return;
    11     }
    12    if(req.url=="/userData" && req.method.toLowerCase()=="post"){
    13        var maindata;
    14        req.addListener("data", function(chunk){
    15            maindata += chunk;
    16            console.log(chunk);
    17        });
    18        req.addListener("end", function(){
    19            var obj = queryString.parse(maindata)
    20            console.log(obj);
    21            console.log(obj.name);
    22            console.log(obj.sex);
    23            res.end("hello");
    24 
    25        });
    26 
    27    }
    28 }).listen(3000,"127.0.0.1");

    html 页面

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title></title>
     6 </head>
     7 <body>
     8    <form method="post" action="http://127.0.0.1:3000/userData" >
     9     name:
    10        <input type="text" name="name">
    11        <br>
    12     sex:
    13        <input type="radio" name="sex" value="man">man
    14        <input type="radio" name="sex" value="female">female
    15        <br/>
    16     <input type="submit" value="submit">
    17 
    18    </form>
    19 </body>
    20 </html>
  • 相关阅读:
    基于lua语言实现面向对象编程
    一.Linux常用命令
    获取线程名称、设置线程名称、获取当前所有线程
    关系型数据库和非关系数据库区别
    Java基础类型之间的转换
    初始化 List 的几种方法
    谷歌浏览器打不开网页,但Opera可以打开网页
    遍历List和Map的几种方法
    java对数组进行排序
    MySQL实现事务隔离的原理:MVCC
  • 原文地址:https://www.cnblogs.com/aytsoft/p/5514236.html
Copyright © 2020-2023  润新知