开发者

Serialize form to a specific json format

When I use .serializeArray(), my data looks like:

[ Object { Name="Name", Value="MyName" }, Object { N开发者_JS百科ame="Age", Value="15"} ]

But I want it to look like:

{ Name: "MyName", Age: 15 }

What do I need to do?

My form:

<form id="newUser">
<input id="Name" name="Name" />
<input id="Age" name="Age" />
<input type="submit" />
</form>


You could write a bit of code which takes the first format and then converts it into the other. Just have it loop over the array and take Name as a key in the object, and Value as the value for the key and assign each pair into a single object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜