Solution to Chinese garbled characters in jquery. form. js of Version 3.01

Source: Internet
Author: User

I searched many methods on the internet, probably because I used jquery. form. js Version 3.01, which was released in March 6 this year (Khan... Is the day before yesterday), so it is generally not useful. I did not confirm whether the earlier version works, but most of them are not responsible for Copy. Some other methods are to encode all the values before submission. I think this is too troublesome. I have added a lot of front-end code, so I didn't take it.
Okay, you can handle it yourself. First, we need to find the entry point to solve the problem. Since we want to encode the data transmitted by JS, we must first start with the data transfer function. I am calling the ajaxSubmit function. Open the js file, find this function, check the source code, and find a line:

Copy codeThe Code is as follows:
Var qx, a = this. formToArray (options. semantic );

FormToArray is used to convert the collected form data into an array of objects and then pass it to Ajax functions such as $. get and $. post. I think there is a drama. But the next code is several hundred lines. To save time, let's go straight to the topic. I set a breakpoint on the line above, input Chinese data on the Web page, and debug the source code step by step through JS. After the program is executed, after several jumps, the last part of the fieldValue function is finally found:

Copy codeThe Code is as follows:
Return $ (el). val ();

In this way, we only need to encode the client here:
Copy codeThe Code is as follows:
Return escape ($ (el). val ());

Then on the Server side, you can use Server. UrlDecode () for decoding. In this way, garbled characters are not displayed and Chinese characters can be correctly accepted ~~~

You can also propose any good methods or suggestions.

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.