最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multipartform data - how to form the nested object in Formdata in javascript - Stack Overflow

programmeradmin2浏览0评论

how to append the nested object in FormData, my object is

{
    name: 'test',
    phone: '454353',
    address: [
        {
            state: 'ewrwer',
            city: 'asdasd'
        }
    ]
}

I had append like this

const data = new FormData();
data.append("name", "test");
data.append("phone", "454353");
data.append("address['state']", "ewrwer");
data.append("address['city']", "asdasd");

but this is not working for me when I send this formData in request body the address is not working.

how to append the nested object in FormData, my object is

{
    name: 'test',
    phone: '454353',
    address: [
        {
            state: 'ewrwer',
            city: 'asdasd'
        }
    ]
}

I had append like this

const data = new FormData();
data.append("name", "test");
data.append("phone", "454353");
data.append("address['state']", "ewrwer");
data.append("address['city']", "asdasd");

but this is not working for me when I send this formData in request body the address is not working.

Share Improve this question asked May 13, 2020 at 10:29 user9361329user9361329
Add a ment  | 

1 Answer 1

Reset to default 7

It should be:

data.append("address[0]['state']", "ewrwer");
data.append("address[0]['city']", "asdasd");

Because, it is inside array of index 0, then inside that you have addresses.

发布评论

评论列表(0)

  1. 暂无评论