express 会自动发起两次请求

1.问题描述,先贴代码和问题图

router.get('/share/:bbsid/:topicid', function (req, res, next) {
    console.log(req.url)
    console.log(req.originalUrl)
    var reqdata = req.params;
    request.post({url:'https://api.xxx.com/bbs/topicDetail/' + reqdata.topicid, form:{topicId: reqdata.topicid}}, function (err, httpResponse, body) {
        body = JSON.parse(body);
        var bbsInfo = body['return']
        //请求评论数据
        request.post({url: 'https://api.xxx.com/bbs/comments/' + reqdata.topicid, form: {topicId: reqdata.topicid, page: 1}}, function (err, httpResponse, body) {
            body = JSON.parse(body)
            var commentdata = body['return'];
            res.render('share',{tree: commentdata,topicInfo: bbsInfo})
        })
    })

});

clipboard.png

看打印的URL
首先这是访问一次页面发生的请求
第一次的值: /share/21/98
然户会自动发起第二次请求,但是这次就没有获取到第二个参数了!
第二次的值: /share/21/undefined;

在线等!!!

阅读 6.2k
2 个回答

我建议你排查客户端发起请求的代码,高概率是客户端js拼写的url就是

/share/21/undefined

认为是客户端的问题,客户端重复发送了 /share/21/undefined

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题