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 ()