第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

表單提交后數(shù)據(jù)無法被nodejs獲?。?/h1>

const fs = require('fs');const qs = require('querystring');require('http').createServer(function (req,res) {    if (req.url === '/'){        res.writeHead(200,{'content-type':'text/html'});        res.end(['<form method="post" action="/url">',            '<input type="text" name="name">',            '<input type="submit">',            '<button>Submit</button>',   //            '</form>'].join(''))    }    else if ('/url' === req.url && req.method==='POST') {        res.writeHead(200,{'content-type':'text/plain'});        var body = '';        req.on('data',function (chunk) {            body += chunk;        });        console.log(body)  //無輸出        res.end('hello world' +qs.parse(body).name +'  end')//輸出undefined     }}).listen(3000);為什么在表單中輸入數(shù)據(jù)后提交 無法被node獲得,body變量無內(nèi)容??
查看完整描述

2 回答

?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

只有req可讀流處理完之后才能響應(yīng),此時(shí)會(huì)觸發(fā)end事件,所以else if邏輯不對(duì),修改后的如下。


 else if ('/url' === req.url && req.method==='POST') {

        res.writeHead(200,{'content-type':'text/plain'});

        var body = '';

        req.on('data',function (chunk) {

            body += chunk;

        });

        req.on('end',function(){

        res.end('hello world' +qs.parse(body).name +'  end')

        })

        

    }


查看完整回答
反對(duì) 回復(fù) 2019-03-23
?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

你log輸出的時(shí)機(jī)不對(duì)


        req.on('data',function (chunk) {

            body += chunk;

            console.log(body); 

        });

        


查看完整回答
反對(duì) 回復(fù) 2019-03-23
  • 2 回答
  • 0 關(guān)注
  • 862 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)