because of the background interface qualification, the form content must be converted to a JSON string submission, thus writing a function that transforms the form's form value into a JSON string. premise: The page introduces jquery directly below the codeOne, the code
/** 表单序列化成json字符串的方法 */ function form2JsonString(formId) { var paramArray = $(‘#‘ + formId).serializeArray(); /*请求参数转json对象*/ var jsonObj={}; $(paramArray).each(function(){ jsonObj[this.name]=this.value; }); console.log(jsonObj); // json对象再转换成json字符串 return JSON.stringify(jsonObj); }
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>12 1
/** form serialization into a JSON string */
2
function form2jsonstring (formId) {
3
var ParamArray = $ (' # '+formId). Serializearray ();
4
/ * Request parameter go to JSON object * /
5
var Jsonobj = {};
6
$ (ParamArray). each (function() {
7
Jsonobj [this. name] = this. value;
8
});
9
console. Log (jsonobj);
10
JSON objects are then converted to JSON strings
11
return JSON. stringify (jsonobj);
12
}
Second, usage
jquery converts form-form values to JSON string functions