I have a page on my web application where I'm trying to create a Person object, which I'm doing through an AJAX POST. The format of the JSON I need to send that the API endpoint is expecting is:
{
"categoryId": "string",
"name": "string",
}
which is easily achievable with this HTML markup:
<form id="form">
<input name="categoryId" value="..." type="hidden" />
<input name="name" type="text" />
<button type="submit">Create</button>
</form>
and then just serializing the data to be passed along with $('#form').serialize()
The problem is that my requirements have changed, and I need to send additional information along - a child collection on the Person. The API endpoint is now expecting this:
{
"categoryId": "string",
"name": "string",
"aliases": [
{
"aliasName": "string",
"position": 0
},
{
"aliasName": "string",
"position": 0
},
{
"aliasName": "string",
"position": 0
}]
}
I'm not sure how I'm supposed to format my HTML markup to accommodate for this. I could set name="aliasName"
and name="position"
on several textboxes, but how can I group them together, and under a parent aliases
?