The solution to the problem of Chinese garbled characters in jquery using Serialize () Form serialization

Source: Internet
Author: User

Serialization of Chinese is garbled because. Serialize () called the Encodeurlcomponent method to encode the data

The workaround is to decode

Cause:. Serialize () automatically calls the encodeURIComponent method to encode the data

Workaround: Call decodeURIComponent (xxx,true); decode the data

Product label
function tag (URL) {
var form = $ (' form '). Serialize (); Serialization of content
var Shuju = decodeuricomponent (form,true); Decode the data
alert (Shuju);
return false;
if (Url.indexof ("?") >= 0) {
var newurl = URL + $ (' form '). Serialize ();
Window.location.href = Newurl;
}else{
var form = $ (' form '). Serialize ();
var Shuju = decodeuricomponent (form,true);
alert (Shuju);
var newurl = url + '? ' + Shuju;
Window.location.href = Newurl;
}
}
  //解决办法:将解码方式unscape换为decodeURI    //原因:浏览器会将url中的中文参数进行encodeURI编码,所以要通过js使用decodeURI进行解码
var url = decodeuri (location.href);  The decodeURI () function decodes a URI encoded by the encodeURI () function.

JQ gets the content of Baidu editor
var test = editor.getcontent ();

The solution to the problem of Chinese garbled characters in jquery using Serialize () Form serialization

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.