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:
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:
return $(el).val();
In this way, we only need to encode the client here:
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.