Domanda

This is a simple sentence. I don't want anything <form><b>but</b></form> this.

But after some client-side html manipulation and...

var newBody = JSON.stringify(req.body);

followed by an update to MongoDb,

var update = { '$set' :{ 'body' : newBody} } 

I have this:

body: '{"This is a simple sentence. I don\'t want anything <form><b>but</b></form> this. ":""}' 

And when I convert it back to html it has curley braces and quotes, which exacerbate with each update. I looked here, and have tried escape back-slashes, but I can't figure it out. Thank you.

{"{\"This is a simple sentence. I <form><b>don't</b></form> want this. \":\"\"}"}
È stato utile?

Soluzione

I believe JSON.stringify is unncessary, assuming you passed post parameters simpleSentance= 'I dont want anything <b>but</b> this'

var newBody = req.body.simpleSentance
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top