Some time ago, when jquery. Validate was used, it encountered a tricky problem. jquery. Validate cannot work normally when the remote verification rule was used. The following is a test script:
< Script >
$ ( Function (){
$ ( " # Form1 " ). Validate ({
Rules :{
Txt1 :{
Remote :{
URL: "http :" // Www.cnblogs.com/a_bu/admin/41022handler2.ashx
, Type: " Post "
, Data :{ " Key " : " SS " }
, Error: Function (A, S, d ){
Alert (S + " " + D);
}< BR >}< br>, messages: {
txt1 :{< br> remote: " Bit empty "
}
}
})
})
< / SCRIPT>
This may be due to compatibility issues. Therefore, jquery 1.44 and jquery 1.51 are used for testing. The results are basically the same. The results are displayed as follows: "error undeined" and "parsererror jquery150000%226654151397_1299202557390 was not Cal ".
If you use fiddler for detection, the server response results are normal. Therefore, server factors are excluded. The problem may occur on the jquery. Validate plug-in itself. Then a solution was found in Google. https://github.com/bigfix/jquery-validation/commit/9aa53f9241224ba349f9fe1b2c801be0f431b63b#undefined, using this alternative, remote verification works fine.
Source code from line 1 to line 2:
// The source file contains about 1087 lines. VaR Ajax = $. Ajax;
VaR Pendingrequests = {};
$. Ajax = Function (Settings ){
// Create settings for compatibility with ajaxsetup
Settings = $. Extend (settings, $. Extend ({}, $. ajaxsettings, settings ));
VaR Port = Settings. port;
If (Settings. Mode = " Abort " ){
If (Pendingrequests [port]) {
Pendingrequests [port]. Abort ();
}
Return (Pendingrequests [port] = Ajax. Apply ( This , Arguments ));
}
Return Ajax. Apply ( This , Arguments );
}; // 1100 rows
Replace:
VaR Pendingrequests = {};
If ($. Ajaxprefilter ){
$. Ajaxprefilter ( Function (Settings, original, jqxhr ){
VaR Port = Settings. port;
If (Settings. Mode = " Abort " ){
If (Pendingrequests [port]) {
Pendingrequests [port]. Abort ();
}
Pendingrequests [port] = Jqxhr;
}
});
} Else {
VaR Ajax = $. Ajax;
$. Ajax = Function (Settings ){
// Create settings for compatibility with ajaxsetup
Settings = $. Extend (settings, $. Extend ({}, $. ajaxsettings, settings ));
VaR Port = Settings. port;
If (Settings. Mode = " Abort " ){
If (Pendingrequests [port]) {
Pendingrequests [port]. Abort ();
}
Return (Pendingrequests [port] = Ajax. Apply ( This , Arguments ));
}
Return Ajax. Apply ( This , Arguments );
};
}
Remote verification test example:
Http://files.cnblogs.com/a_bu/validate.test.zip
Another way to fix: http://www.cnblogs.com/a_bu/archive/2011/03/06/1972202.html