Home > Article > Web Front-end > Form form submission data problem
Submitting data through form forms is not difficult at all, but it can become difficult if you don’t handle it well!
A method that has been encapsulated by javascript is serialize(), but this method is to load the form data into key1=value1&key2=value2&... Everyone knows that this format is not Json format, and the data in this format is passed to the background JSONObject .parseObject() cannot be parsed! ! !
So in order to conveniently use JSONObject to convert the data from the front desk into java objects, the author prefers to use the following method:
$.fn.serializeJson=function(){
var serializeObj={};
var array= this.serializeArray();
var str=this.serialize();
using using using using using using ‐ ‐ ‐ var str=this. ‐ ‐ ‐ ‐ var str=this. Multi -choice f IF ($. Isarray (Serializeobj [this.Name])) {
if (this.value) {// The options of the second one after the check box are valuable [except empty string, null, undefinded] Only then will enter er SerializeObj [this.Name] .push (this.value);
}} else {
if (this.value) {// The second option is worth it. null, undefinded ] will enter
serializeObj serializeObj serializeObj
}); t Return Serializeobj;
};
This is to serialize the form form data into JSON objects, and then use json.stringify () to transparent json objects into json fonts to the background!