문제

I'm doing an ajax $.post to a node.js route which inserts into a mongodb collection

collection.insert(req.body.content, function () {
    return req.body.content
});

How do I return something so that I can do something with the response in the client callback?

For example in php I can echo.

도움이 되었습니까?

해결책

you should have access to the request object (req in your example) and a response object. All you need to do is write to the response object.

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'); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top