javascript - nodejs+express如何在router.post 請求內(nèi)再發(fā)送一次 axios.post請求
問題描述
前端 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); });});
錯誤提示
TypeError: Converting circular structure to JSON
**axios.post能獲取到接口返回的數(shù)據(jù),但是前端并沒有得到axios.post返回的數(shù)據(jù)。**
問題解答
回答1:res.json({data : _data});使用 util.inspect 參考http://blog.csdn.net/isaisai/...回答2:問題已解決,把 req.req.session.user = response.data 即可
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. docker鏡像push報錯3. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題4. javascript - 在 model里定義的 引用表模型時,model為undefined。5. 利用IPMI遠(yuǎn)程安裝centos報錯!6. node.js - mongodb查找子對象的名稱為某個值的對象的方法7. 運行python程序時出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯誤?8. html5和Flash對抗是什么情況?9. phpstudy8.1沒集成mysql-front10. 前端 - @media query 使用出現(xiàn)的問題?

網(wǎng)公網(wǎng)安備