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

Source: Internet
Author: User
Form submission using previous projects

Use the form () method to detach the submit event from the Submit button and bind to any event
Copy Code code as follows:

function Addsubmit () {
$ (' #addForm '). Form (' Submit ', {
URL: _basepath + '/@Controller/@RequestMapping ',
Onsubmit:function () {
if (Boolean) {//placement can be submitted in judgment condition
$.messager.show ({
Title: ' Hint ', msg: ' does not conform to the preservation condition ',
ShowType: ' fade ', style:{right: ', Bottom: '}
});
Return false;//block form submission
}
return $ (' #addForm '). Form (' validate ');//Determine if all required items have a value
},
Success:function (data) {
var obj = Jquery.parsejson (data);//Convert the returned JSON to the desired object (responsedata)
if (!obj.success) {//To determine the property value of the indicated state in the returned ResponseData object
$.messager.show ({
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
}
}
});
}

This is another way of submitting in sharp jquery today, using Ajax to encapsulate the form content with post submission
Copy Code code as follows:

$ ("#btn"). Click (function () {
$.get ("get.php", {username:$ ("#username"). Val (), password:$ ("#password"). Val ()}, function (data, textstatus) {// The data in the form is taken out and then encapsulated and uploaded
$ ("#target"). HTML (data);//fill the return value into the page
});
});

Then there is a simplified version, using the Serialize () method to serialize
Copy Code code as follows:

$ ("#btn"). Click (function () {
$.get ("get.php", $ ("#form"). Serialize (), function (data, textstatus) {///the form is removed and uploaded
$ ("#target"). HTML (data);//fill the return value into the page
});
});

The serialize () method can be encoded automatically and can be converted using objects other than the form, such as a checkbox

There is also a Serializearray () method that serializes an element and returns a JSON object in the form of an array, not a JSON string

That is, you do not need to use the Jquery.parsejson () method to convert

The return value can be manipulated directly using a method such 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.