Node.js在成功插入Mongo后做出回应?
-
11-10-2019 - |
题
我正在做一个ajax $。
collection.insert(req.body.content, function () {
return req.body.content
});
我如何返回某些东西,以便可以对客户端回调中的响应做些事情?
例如,在PHP中,我可以回声。
解决方案
您应该可以访问请求对象(示例中的REQ)和响应对象。您需要做的就是写入响应对象。
res.writeHead(200, {
'Content-type': 'text/plain' // or whatever content type you want
});
// you can use res.write also, but call end when you are done.
res.end('the text you want to send');
不隶属于 StackOverflow