Domanda

che sto facendo un $ .post Ajax per un node.js percorso che inserisce in una collezione mongodb

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

Come faccio a restituire qualcosa in modo che io possa fare qualcosa con la risposta nella richiamata cliente?

Per esempio in php posso eco.

È stato utile?

Soluzione

si dovrebbe avere accesso all'oggetto richiesta (req nel tuo esempio) e un oggetto di risposta. Tutto quello che dovete fare è scrivere l'oggetto di risposta.

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'); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top