将表单转成JSON提交:jquery html json forms
jopen
10年前
draft 的一个jQueyr实现,用于将表单转成JSON格式提交。
用法:
Include the script in your page and any form with an attribute of enctype set to 'application/json' will submit data with a json payload.
<form enctype='application/json'> <input name='places[0][city]' value='New York City'> <input type='number' name='places[0][population]' value='8175133'> <input name='places[1][city]' value='Los Angeles'> <input type='number' name='places[1][population]' value='3792621'> <input name='places[2][city]' value='Chicago'> <input type='number' name='places[2][population]' value='2695598'> </form>
produces
{ "places": [ { "city": "New York City", "population": 8175133 }, { "city": "Los Angeles", "population": 3792621 }, { "city": "Chicago", "population": 2695598 } ] }
To disable json post submission, call $.JSONform.disable()
.
To enable, $.JSONform.enable()
.
Call $(formElement).JSONencode()
to get a JSON object representing formElement.