jquery converts form-form values to JSON string functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.