Validation of form submission in jquery and implementation of serialized form content

Source: Internet
Author: User
Tags bind json

The form submission method used in the project prior to  , using the form () methods to detach the submit event from the Submit button and bind to any event, here's a good example to see below

Forms submitted in previous projects     use the form () method to detach the submit event from the Submit button and bind to any event   code as follows: Function Addsubmit () {  $ (' # AddForm '). Form (' Submit ', {  URL: _basepath + '/@Controller/@RequestMapping ',  onsubmit:function () {  if (Boolean) {//placement can submit judgment conditions   $.messager.show ({  title: ' Hint ', msg: ' does not conform to the save condition ',  showtype: ' fade ', Style:{right: ', Bottom: '} } ';  return false;//block form submission  }  (' #addForm '). Form (' Validate '); To determine whether all required items are of value  },  success:function (data) {  var obj = Jquery.parsejson (data); Converts the returned JSON to the desired object (responsedata)   if (!obj.success) {//To determine the property value   $.messager.show of the indicated state in the returned ResponseData object ({   title: ' Hint ', msg: ' Save failed ',  showtype: ' fade ', style:{right: ', bottom: '} } '; } else {  $. Messager.show ({  title: ' Hint ', msg: ' Save Success ',  showtype: ' fade ', style:{right: ', bottom: '} } ');  $ ("# Addwin "). Window (" close ");/Turn off commit pwkk  query ()//Refresh result set  } } }); }    today in the sharpJQuery also reads a submission that uses Ajax to encapsulate the form content with post submission   code as follows: $ ("#btn"). Click (function () {  $.get ("get.php", {username: $ ("#username"). Val (), password:$ ("#password"). Val ()}, function (data, textstatus) {///post the data in the form as a package upload   $ ("# Target "). HTML (data)//fill the return value into the page  }); });    then a simplified version, using the Serialize () method serialization   code as follows: $ (" #btn "). Click (function () {  $.get ("get.php", $ ("#form"). Serialize (), function (data, textstatus) {///The data in the form is taken out and encapsulated and uploaded   $ ("#target"). HTML (data)//Fill return value to page  }); });    Serialize () method can be automatically encoded, Also, objects such as a checkbox, other than forms, can be converted     also have the Serializearray () method to serialize the elements and return the JSON object in the form of the array, not the JSON string     That is, you do not need to use the Jquery.parsejson () method for conversion     return values directly using such methods as $.each ()  

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.