jquery Ajax post Chinese code garbled solution

Source: Internet
Author: User

encodeURIComponent will be encoded in Utf-8, under GBK encoding, can you encode it with GBK?

If you are still playing encodeuricomponent idea, then sorry, encodeURIComponent will only utf-8 code, and no other API to do other coding; but don't worry, look at the following:

encodeURIComponent, it is to convert Chinese, Korean and other special characters into utf-8 format of the URL encoding.

Escape encodes a Unicode value other than 0-255 by outputting the%u**** format, in other cases the Escape,encodeuri,encodeuricomponent encoding results are the same.

Haha, see hope? Yes, it is to use escape instead of encodeURIComponent method, but must note:

Escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z

There are 71 encodeuricomponent characters that are not encoded:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

When you use escape, you must encode the plus sign, otherwise, when the content contains the plus sign, it will be translated into space by the server.

$.ajax ({
Url:ajaxurl,
Type: ' Post ',
DataType: ' HTML ',
timeout:20000,//Timeout Time setting
data:para,//parameter settings
Success:function (HTML) {
}
});

Ajax:function (s) {
Extend the settings, but Re-extend ' s ' So, it can be
Checked again later (in the test suite, specifically)
s = Jquery.extend (true, S, Jquery.extend (true, {}, jquery.ajaxsettings, s));
var jsonp, jsre =/=? (&|$)/g, status, data,
Type = S.type.touppercase ();
Convert data if not already a string
if (s.data && s.processdata && typeof s.data!== "string")
S.data = Jquery.param (S.data);
........
}

Jquery.param=function (a) {
var s = [];
var encode=function (str) {
Str=escape (str);
Str=str.replace (/+/g, "%u002b");
return str;
};
function Add (key, value) {
s[s.length] = encode (key) + ' = ' + encode (value);
};
//If a array was passed in, assume this is it's an array
//of form elements
if (Jquery.isarray (a) | | a.jq uery)
//Serialize the form elements
Jquery.each (A, function () {
Add (this.name, this.value);
});
//Otherwise, assume that it's an object of key/value pairs
Else
//serialize the Key/values
for (var J in a)
//If the ' is ' an array then the ' key names need to be repeated
if (Jquery.isarray (a[j))
JQ Uery.each (A[j], function () {
Add (j, this);
});
Else
Add (J, Jquery.isfunction (A[j])? A[j] (): A[j]);
//Return the resulting serialization
Return S.join ("&"). Replace (/%20/g, "+");
}

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.