The form submission method used in the previous project. The form () method can be used to separate the submission event from the submit button and bind it to any event, the following is a good example. You can refer to the form submission method used in the previous project.
The form () method can be used to separate the submitted event from the submit button and bind it to any event.
The Code is as follows:
Function addSubmit (){
$ ('# Addform'). form ('submit ',{
Url: _ basePath + '/@ Controller/@ RequestMapping ',
OnSubmit: function (){
If (boolean) {// conditions for determining whether to submit
$. Messager. show ({
Title: 'hup', msg: 'Do not meet the Save condition ',
ShowType: 'fade ', style: {right: '', bottom :''}
});
Return false; // block form submission
}
Return $ ('# addForm'). form ('validate'); // checks whether all required items have values.
},
Success: function (data ){
Var obj = jQuery. parseJSON (data); // convert the returned JSON to the desired object (ResponseData)
If (! Obj. success) {// determines the attribute value of the Status indicated in the returned ResponseData object
$. Messager. show ({
Title: 'hs', msg: 'failed to save ',
ShowType: 'fade ', style: {right: '', bottom :''}
});
} Else {
$. Messager. show ({
Title: 'hs', msg: 'saved successfully ',
ShowType: 'fade ', style: {right: '', bottom :''}
});
$ ("# AddWin"). window ("close"); // close the submission of pwkk
Query (); // refresh the result set
}
}
});
}
Today, I read this submission method in sharp jQuery, Using ajax to encapsulate the form content and using post to submit.
The Code is as follows:
$ ("# Btn"). click (function (){
$. Get ("get. php ", {username: $ (" # username "). val (), password: $ ("# password "). val ()}, function (data, textStatus) {// extract the data in the form one by one and then encapsulate and upload the data
$ ("# Target" ).html (data); // fill in the returned value to the page
});
});
Then there is a simplified version that uses the serialize () method for serialization.
The Code is as follows:
$ ("# Btn"). click (function (){
$. Get ("get. php", $ ("# form"). serialize (), function (data, textStatus) {// extract the data in the form one by one and encapsulate the upload
$ ("# Target" ).html (data); // fill in the returned value to the page
});
});
The serialize () method can be automatically encoded, and objects other than forms such as checkbox can also be converted using it.
In addition, the serializeArray () method can serialize elements and return JSON objects in array format instead of JSON strings.
You do not need to use the jQuery. parseJSON () method for conversion.
You can directly use methods like $. each () to return values.