Jquery. Validate 1.7 (Remote Method) bug fixes (1)

Source: Internet
Author: User

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

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.