html - node.js为啥抓取不了前端传过来的数据?
ringa_lee
ringa_lee 2017-04-17 15:00:14
[Node.js讨论组]

用node.js抓取不了前端表单的数据,哭哭哭
这是node.js代码

var http=require("http");
var url=require("url");
var dns=require("dns");
var fs=require("fs");
var querystring=require("querystring");
var postdata="";
http.createServer(function(req,res){
    
        req.setEncoding("utf8");
    //var readPath=dirname+"/"+url.parse('a.html').pathname;
    var pathname=url.parse(req.url).pathname;

    if(pathname==="/"){
        res.writeHead(200,{'Content-Type':'text/html'});
        var indexpage=fs.readFileSync("a.html");
    //console.log(indexpage);
    res.end(indexpage);
    }
    if(pathname==="/about"){
        res.writeHead(200,{'Content-Type':'text/plain'});
        
        
        req.addListener("data",function(chunk){
            if(chunk){
                postdata+=chunk;
               console.log(chunk);
            }
            
            else
                console.log("no data emit")
        });
            req.addListener("end",function(postdata){
                var a=querystring.parse(postdata);
                console.log(postdata)
                console.log(a);
                res.end(a.text);
            });
        }

    
    console.log("Server has been running on port 3000");
    
}).listen("3000","127.0.0.1");

这是HTML代码







求大神指教

ringa_lee
ringa_lee

ringa_lee

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

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