JS Code:
1$(function() {2$ (' #form '). Validate ({3OnKeyUp:false,4 rules: {5 oldpassword:{6Requiredtrue,7 Remote: {8Url:global.context + '/admin/password/duplicate ',9 data: {TenOldPassword:function() { One return$ (' #oldPassword '). Val (); A } - } - } the }, - Password: { -Required:true, -Minlength:6 + }, - repeat: { +Required:true, AMinlength:6, atEqualto: ' #password ' - } - }, - messages: { - oldpassword:{ -Required: ' Please enter the original password ', inRemote: ' Please enter the correct original password ' - }, to Password: { +Required: ' Please enter your password ', -MinLength: ' length must be greater than 6 ' the }, * repeat: { $Required: ' Please confirm password ',Panax NotoginsengEqualto: ' Two input passwords inconsistent ', -MinLength: ' length must be greater than 6 ' the } + }, ASubmithandler:function(form) { the varPassword = $ (' #password '). Val (); + varRepeat = $ (' #repeat '). Val (); - $.ajax ({ $Url:global.context + '/admin/password ', $Type: ' Put ', -ContentType: "Application/json; Charset=utf-8 ", - data:JSON.stringify ({ the Password:password, - repeat:repeatWuyi }), theSuccess:function(data) { - console.log (data); Wu if(data.status== ' Success '){ -Alert ("Change Password succeeded"); About } $ } - }); - } - }); A});
Personal feeling is more useful, you can use validate framework to verify elements.
Jquery Validate (Submithandler function) validation by sending Ajax