JS processing Chinese garbled records/nodejs+express error 413

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.