문제

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. \":\"\"}"}
도움이 되었습니까?

해결책

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