JQuery Validator verifies the Ajax form submission method and Ajax parameter passing method, jqueryvalidator
The serialize () method creates a URL encoded text string by serializing the form value. Instead of passing parameters one by one
Previous ajax parameter passing Methods
$.ajax({ url : "${ctx}/SJStandardDamPartition/insertOrUpdateDamPartition", type : "post", dataType : "json", data: {beginsectionid:function(){ return $('#number option:selected').val(); }, beginelevation:function(){ return $('#onset').val(); }, endelevation:function(){ return $('#end').val(); } }, success : function(result) { } });
Use the parameter passing method of serialize ()
var param = $("#standForm").serialize(); $.ajax({ url : "${ctx}/SJStandardStandardInfo/insertOrUpdateStandardInfo", type : "post", dataType : "json", data: param, success : function(result) { } });
In some slightly complicated business scenarios, we may encounter situations where multiple forms are required to be on the same page. However, after submitting a form, we do not want to refresh or jump to the page, so what we are considering is Ajax form submission. How can we make the validator plug-in of jQuery verify the form submitted asynchronously? Let's continue.
Here, I will illustrate it with an example on the network.
The following is a common jquery. ajax form submission method.
$ ("# SubmitButton "). click (function () {// serialized form var param = $ ("# leaveSave "). serialize (); $. ajax ({url: "leaveSave. action ", type:" post ", dataType:" json ", data: param, success: function (result) {if (result = 'success') {location. href = 'allrequisitionlist. action ';} else if (result. startWith ("error _") {$ ("# errorMessage" 2.16.html (result. substring (6);} else {// The returned result is converted to JSON data var jsonObj = eval ('+ result + ')'); startTime = $ ("# startdate "). val (); endTime = $ ("# enddate "). val (); hour = jsonObj. hour; reason = jsonObj. reason; replaceDom (startTime, endTime, hour, reason );}}});});
If you want to use ajax to submit a form and jquery's validate for verification, you can solve this problem: the form is still the normally written form content, and the type is also the submit type, only use ajax to submit the form in the method after the validate verification is passed
$ ("# SaveWorkExtra "). validate ({onsubmit: true, // whether to verify onfocusout: false when submitting, // whether to verify onkeyup: false when getting focus, // whether to verify rules when hitting the keyboard: {....}, messages :{....}, submitHandler: function (form) {// callback var param =$ ("# saveToWorkExtra") after passing "). serialize (); $. ajax ({url: "workExtraChange. action ", type:" post ", dataType:" json ", data: param, success: function (result) {if (result = 'success') {location. href = 'allrequisitionlist. action ';} else {var jsonObj = eval (' + result + ') ;}}) ;}, invalidHandler: function (form, validator) {// If the callback fails, return false ;}});
Summary
The above section describes the jQuery Validator method used to verify Ajax form submission and Ajax parameter passing. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!