html5 - 通过post抓取的页面数据 为啥不能展现在页面上
PHPz
PHPz 2017-04-17 15:01:39
[Node.js讨论组]

这是node.js代码

var http = require("http"),
    fs = require("fs"),
    querystring = require("querystring"),
    url = require("url");

http.createServer(function(req,res){
    var postdata="";
    var query="what";
    var pathname = url.parse(req.url).pathname;

    req.setEncoding("utf8");
    if(pathname=="/"){
        var indexPage = fs.readFileSync("表单.html");
        res.writeHead(200,{"Content-Type":"text/html"});
        res.end(indexPage);
    }
    if(pathname=="/about"){
        req.on("data",function(chunk){
            postdata += chunk;
        });
        req.on("end",function() {
            console.log(postdata);
            query = querystring.parse(postdata);
            console.log(query);
        });
        res.writeHead(200, {"Content-Type":"text/plain"});
        console.log(query.Name);
        console.log(query.number);
        res.write(query.number+ "and "+query.number);
        res.end();
    }
    else{
        res.writeHead(404,{"Content-Type":"text/plain"});
        res.end("Can not find the source");
    }
}).listen(2000,"127.0.0.1");

console.log("The server is running at port 2000");

这是html代码




    
    表单填写


Name:

SchoolNumber:

执行结果图:

求大神解决 小弟感激不尽

PHPz
PHPz

学习是最好的投资!

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号