In the AJAX submission of data, due to the Chinese full-width characters and so on, the server side received after the display garbled, the specific performance is: \u00000\u000023 and so on (I want to restore the wrong scene, altogether appear, and so the next time in the show, I put the garbled stickers out, The following specific solutions):
Details reasons do not explain that they can go to Baidu
Garbled:
var n = $("#id").html();$.ajax({ type: ‘post‘, dataType: ‘json‘, url: ‘/‘, contentType: "application/x-www-form-urlencoded; charset=utf-8", data: n, success: function(data) { console.log(data); }});
After resolution:
var n = $("#id").html();var _n = encodeURIComponent((encodeURI(n, "UTF-8")));$.ajax({ type: ‘post‘, dataType: ‘json‘, url: ‘/‘, contentType: "application/x-www-form-urlencoded; charset=utf-8", data: _n, success: function(data) { console.log(data); }});
In fact, add encodeURIComponent encodeURI
Decoding on the server side:
decodeURI(decodeURIComponent(escape(bodys)), "UTF-8")
By the way to record JS after encode post submitted to the Nodejs backend, Nodejs reported 413 error, in fact, the modification method is very simple, modify the following two lines can (50m is not a bit big ah ...). ):
app.use(bodyParser.json({limit: ‘50mb‘}));app.use(bodyParser.urlencoded({limit: ‘50mb‘, extended: true}));
JS processing Chinese garbled records/nodejs+express error 413