Some time ago, the AJAX Chinese encoding problem occurred again, leading to duplicate member name detection failure. However, the problem occurred this time due to the remote verification of the Validation plug-in. Based on the previous experience
The Code is as follows:
ContentType: "application/x-www-form-urlencoded; charset = UTF-8 ",
Added to the parameters of the ajax request, the result does not work this time.
After observing the result of Fiddler multiple times and finding it invalid, I had to open JQuery. Validation. js to seek the answer.
In the remote code, I found that:
The Code is as follows:
...
Var data = {};
Data [element. name] = value;
$. Ajax ($. extend (true ,{
Url: param,
Mode: "abort ",
Port: "validate" + element. name,
DataType: "json ",
Data: data,
....
Originally, the plug-in defined the submitted data and sent the data to be verified to the server in json format. No wonder the encoding definition for form is invalid. EncodeURIComponent (value) will be forcibly encoded on the value immediately. That's all!
Postscript:
This method must be used to explicitly decode the data when the server code is processed. As a result, we will go back to the starting point to study better methods.
To prevent the Validation plug-in from processing input data, I tried to use my own Option to overwrite the Option definition of the Validation:
The Code is as follows:
Remote :{
Url: "ajax. aspx? A = xxx ",
Type: "post ",
DataType: "json ",
ContentType: "application/x-www-form-urlencoded; charset = UTF-8 ",
Data: {txt1: function () {return $ ("# txt1"). val ();}}
}
Then, in the server code, obtain the corresponding data in the Form data, which avoids the modification to the Validation and meets my requirements.
Link: http://www.luyuliang.com/post/chinese-issue-in-jquery-validation-plugin.aspx