Ultimate brute force solution for jquery Ajax Chinese garbled characters under GBK Encoding

Source: Internet
Author: User

Ah, it's still an old topic. It's always around Chinese people ......

Let's go
The project uses version 1.2.6 in the early stage and Version 1.3.2 in the later stage;

Let's talk about the implementation method. It's a bit violent-directly modify the jqury source code, but don't worry, it won't affect the overall function, and you can fix the garbled code by modifying a few lines of code, that is, when sending a request, transcode the parameter value again. The modification method isParam

 

1. jquery1.2.6Garbled Solution

  • Open the source file version 1.2.6
  • Locate the rows 2,911st, 2921, and 2924, and modify the corresponding parameter values to enclose the encodeuricomponent. The modified result is as follows:Param: function (a) {<br/> var S = []; </P> <p> // If an array was passed in, assume that it is an array <br/> // of form elements <br/> If (. constructor = array |. jquery) <br/> // serialize the form elements <br/> jquery. each (A, function () {<br/> S. push (encodeuricomponent (this. name) + "=" + encodeuricomponent (this. value); <br/>}); </P> <p> // otherwise, assume that It's an object of key/value pairs <br/> else <br/> // serialize the key/values <br/> for (VAR j In) <br/> // if the value is an array then the key names need to be repeated <br/> if (a [J] & A [J]. constructor = array) <br/> jquery. each (A [J], function () {<br/> S. push (encodeuricomponent (j) + "=" + encodeuricomponent (this); <br/>}); <br/> else <br/> S. push (encodeuric Omponent (j) + "=" + encodeuricomponent (jquery. isfunction (A [J])? A [J] (): A [J]); </P> <p> // return the resulting serialization <br/> return S. join ("&"). replace (/% 20/g, "+"); <br/>}< br/>

Download: jquery-encode-gbk.1.2.6.js
Download: jquery-encode-gbk.pack.1.2.6.js

 

2. jquery1.3.2Garbled Solution

1.3.2 does not need to be so troublesome, because this version simplifies the structure of the param method and only needs to modify a line of code, because transcoding is only available in one place.

Locate row 3,737th and enclose an encodeuricomponent. The result is as follows:

Param: function (a) {<br/> var S = []; </P> <p> function add (Key, value) {<br/> S [S. length] = encodeuricomponent (key) + '=' + encodeuricomponent (value); <br/>}; <br/>

Download: jquery-encode-gbk-1.3.2.js
Download: jquery-encode-GBK-. pack.1.3.2.js

 

 

 

Reprint please indicate the source http://blog.csdn.net/shimiso

Technical Exchange Group: 173711587

Related Article

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.