为什么使用get请求获取下载计数?您不需要这样做来更新nodejs后端中的下载计数。相反,为什么不在下载完成后触发一个post请求,并处理路由模型中计数的更新呢?所以你不必担心任何延迟问题。
假设你在MongooseJS中使用Mean Stack,这里有一个关于我的想法:
router.post('/update', (req, res)=>{
user.findById(id, function (err, data) { //Send some parameter in the POST request so as to uniquely identify whichever entry you wish to update the download_count of
if (err) console.log(err);
var new_download_count = data.download_count + 1; //Updating count
data.set({ download_count: new_download_count }); //Saving new count
data.save(function (err, updatedData) {
if (err) console.log(err);
res.send(updatedTank); //Indicate new object
});
});
});