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

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

express4.x 框架 req.body獲取不到前臺(tái)post數(shù)據(jù)

express4.x 框架 req.body獲取不到前臺(tái)post數(shù)據(jù)

海綿寶寶撒 2019-04-10 20:49:11
varoption={type:"POST",url:"/",contentType:"application/json;charset:utf-8",dataType:"json",data:{ok:"on",temperature:"18",}success:function(response){console.log(response);}error:function(err){alert(err);}}$.ajax(option);以上是前臺(tái)代碼。。app.post("/",function(req,res){vardata={ok:req.body.ok,temperature:req.body.temperature}console.log(data);})最后輸出的為{ok:undefined,temperature:undefined}我使用的express框架.app.use(bodyParser());app.use(bodyParser.json());app.use(bodyParser.urlencoded({extended:true}));使用的bodyParser解析的模塊。但是依然解析不到req.body里面的值。
查看完整描述

2 回答

?
幕布斯7119047

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

jquery的ajax方法里,設(shè)置contentType是用來設(shè)置請(qǐng)求的contentType,而請(qǐng)求的contentType只有3種:application/x-www-form-urlencoded(默認(rèn)值)、multipart/form-data、text/plain,application/json一般會(huì)是響應(yīng)的contentType,而在jquery的ajax方法里,要用dataType:'json',來把設(shè)置響應(yīng)的contentType設(shè)置為json
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-10
?
慕的地6264312

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

Express(4.x)的最新版本已經(jīng)將bodyparser中間件從核心框架中分離出來了。如果你需要bodyparser,你應(yīng)該單獨(dú)安裝一個(gè)
npminstallbody-parser--save
接著
varapp=express()
//parseapplication/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended:false}))
//parseapplication/json
app.use(bodyParser.json())
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-10
  • 2 回答
  • 0 關(guān)注
  • 3238 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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