javascript - nodejs+express如何在router.post 請(qǐng)求內(nèi)再發(fā)送一次 axios.post請(qǐng)求
問(wèn)題描述
前端 login.js
$.post('/user/login',{userName : username},function (data) { if(data.error) return console.log(data.error);console.log(data)})
后端 user.js
router.post(’/login’,function(req,res,next){ axios.post(’http://’+node_nev+'/api/zhibo/room?userName='+req.body.userName).then(function (response) {// console.log(response); if(response.data.code){req.session.user = response; var _data = { 'username':response.data.data.username}; res.json({data : _data});}else{ res.json({error : 'Data Error!'})} }) .catch(function (error) {console.log(error); });});
錯(cuò)誤提示
TypeError: Converting circular structure to JSON
**axios.post能獲取到接口返回的數(shù)據(jù),但是前端并沒(méi)有得到axios.post返回的數(shù)據(jù)。**
問(wèn)題解答
回答1:res.json({data : _data});使用 util.inspect 參考http://blog.csdn.net/isaisai/...回答2:問(wèn)題已解決,把 req.req.session.user = response.data 即可
相關(guān)文章:
1. javascript - 微信網(wǎng)頁(yè)開(kāi)發(fā)從菜單進(jìn)入頁(yè)面后,按返回鍵沒(méi)有關(guān)閉瀏覽器而是刷新當(dāng)前頁(yè)面,求解決?2. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?3. mysql replace 死鎖4. mysql - C#連接數(shù)據(jù)庫(kù)時(shí)一直這一句出問(wèn)題int i = cmd.ExecuteNonQuery();5. python - 數(shù)據(jù)與循環(huán)次數(shù)對(duì)應(yīng)不上6. extra沒(méi)有加載出來(lái)7. android - 安卓做前端,PHP做后臺(tái)服務(wù)器 有什么需要注意的?8. 環(huán)境搭建 - anaconda 創(chuàng)建python2.7環(huán)境中打開(kāi)編譯器確是3.6版本9. php傳對(duì)應(yīng)的id值為什么傳不了啊有木有大神會(huì)的看我下方截圖10. mysql - ubuntu開(kāi)啟3306端口失敗,有什么辦法可以解決?
