Home >Java >javaTutorial >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 using ‐ ‐ ‐ ‐ var str=this.serialize(); 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] will enter
serializeObj[this.name] if(this.value){ // The second option of the check box has a value [Except empty string, null, undefinded] will enter
SerializeObj [This.name] = [SerializeObj [This.name], this.value]; = this.value;
}
}); 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!