Question about Remote verification in JQuery's Validation plug-in

Source: Internet
Author: User

Based on the previous experience

Copy codeThe 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:
Copy codeThe 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:

Copy codeThe 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

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.