Home > Web Front-end > JS Tutorial > body text

Solution to the Chinese garbled problem of jquery.form.js version 3.01_jquery

WBOY
Release: 2016-05-16 17:55:30
Original
1101 people have browsed it

I searched a lot of methods on the Internet, maybe because the jquery.form.js I used is version 3.01, which was only released on March 6 this year (sigh... the day before yesterday), so it generally doesn't work. As for whether the lower version works, I have not verified this, but most of them are still irresponsible Copy Copy Copy. There are also some methods that encode all the values ​​before submission. I think this is too troublesome and adds a lot of extra front-end code, so I didn't take it.
Okay, let’s handle it ourselves. First we need to find the entry point, which is the entrance to solving the problem. Since we want to encode the data passed by JS, we must first start with the data transfer function. I'm calling the ajaxSubmit function, that's it. Open the js file, find this function, look at the source code, and find a line:

Copy the code The code is as follows:

var qx, a = this.formToArray(options.semantic);

The function of formToArray is to convert the collected form data into an object array and then pass it to $.get , $.post and other Ajax functions. I think there's a chance. However, there are hundreds of lines of code that follow. To save time, let’s go straight to the topic. I set a breakpoint on the above line, input Chinese data on the Web page, and understand the source code through step-by-step JS debugging. After the program was executed, after several jumps, I finally found the last part of the fieldValue function:

Copy code The code is as follows:

return $(el).val();

In this way, we only need to encode the client here:
Copy code The code is as follows:

return escape($(el).val());

Then on the server side, you can use Server.UrlDecode() to decode, so that garbled characters will no longer appear and Chinese characters can be accepted correctly~~~

Do you have any good methods or suggestions? It can also be brought up.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!