Home  >  Article  >  Web Front-end  >  Chinese problem with Remote validation in JQuery's Validation plug-in_jquery

Chinese problem with Remote validation in JQuery's Validation plug-in_jquery

WBOY
WBOYOriginal
2016-05-16 18:22:301142browse

Based on the last experience, I will copy the code

as follows: contentType: "application /x-www-form-urlencoded; charset=utf-8",
was added to the parameters of the ajax request, but it didn’t work this time.
After observing the Fiddler results many times and finding that it was invalid, I had to open JQuery.Validation.js to find the answer.

In the remote code, I found:



Copy the code 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,
....


It turns out that the plug-in defines the submitted data and directly transmits the data to be verified to the server in json format. No wonder the encoding definition for the form is invalid, and the value is forced to encodeURIComponent(value), and it works!
Postscript:

This method must explicitly decode the data when processed by the server code, and its versatility is very poor. Therefore, I will go back to the starting point to study a better method. >
In order to prevent the Validation plug-in from processing the input data, I tried to use my own Option to override Validation’s Option definition:





Copy code
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-side code, obtain the corresponding data in the Form data, thus avoiding the modification of Validation and meeting my requirements.
Original link:
http://www.luyuliang.com/post/chinese-issue-in-jquery-validation-plugin.aspx
Statement:
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