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

Source: Internet
Author: User
Recently, a fom plug-in of jquery was used. It is a jQuery plug-in that fully supports forms. When I submitted FormPost using ajaxSubmit yesterday, I found that the Chinese data retrieved by the server was garbled. This may be because jquery is UTF-8 and does not support many search methods on gb2312. It may be because of the jquery I used. form. js is Version 3.01, that is, the version (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:

The 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:

The Code is as follows:


Return $ (el). val ();


In this way, we only need to encode the client here:

The 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.
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.