Jquery formvalidator plug-in is a good domestic validation plug-in, it is very convenient to do some common verification, but recently encountered a problem that if the form is submitted by AJAX, you cannot follow the traditional practice, for example:
Copy codeThe Code is as follows: $ ajax. post ("...............")
$. FormValidator. initConfig ({formID: "applyForm", onError: function (msg) {alert (msg )}});
$ ("# Reason"). formValidator (). inputValidator ({min: 1, onErrorMin: 'Enter the application content and reason '});
Unfortunately, the result of submitting an ajax form and using formvalidator for verification is not met. If you want to use both formvalidator and ajax for submission, you will first see the usage of ajaxform in the formvalidtor manual.Copy codeThe Code is as follows: $. formValidator. initConfig ({theme: "Default", submitOnce: true, formID: "form1", ajaxForm :{
DataType: "html ",
Buttons: $ ("# button "),
Url: "http://www.51gh.net/chkuser.aspx? Act = OK"
},
OnError: function (msg, obj, errorlist ){
$ ("# Errorlist"). empty ();
$. Map (errorlist, function (msg ){
$ ("# Errorlist"). append ("[*]" + msg +"
")
});
Alert (msg );
},
SubmitAfterAjaxPrompt: 'The data is being asynchronously verified. Please wait ...'
});
After reading this, this method seems acceptable, but in fact, it is not very helpful to Chinese.
Struts2, spring 3, tomcat is also using UTF-8, sturts2 and so on all encoded with a UTF-8, but it is still said that when take
When speaking of struts2's Chinese value:
Org. apache. tomcat. util. http. Parameters processParameters
Warning: Parameters: Character decoding failed. Parameter skipped.
Java. io. CharConversionException: isHexDigit.
For the solution, see:
Http://www.iteye.com/problems/7099
However, this problem is very strange, and it is too troublesome to use formvalidtor, so I found another method, which is really easy to use.Copy codeThe Code is as follows: if ($. formValidator. pageIsValid ('1') = true)
{
$. Post ("xxxxxxxxxxxxxxxxx ")
}
Other validation rules are still written. If there is only one form on the page, the default value is 1. The pageIsValid here is used to verify that all the controls in this group have passed the verification and continue to do something, you see, this is much simpler.