

FormData传数组对象的方法
source link: https://segmentfault.com/a/1190000040452911
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

FormData传数组对象的方法
前端formData传参,有时候需要传递数组对象,如果直接给变量append一个数组对象后台无法接受。
const arr = [ {name: 'zxc', age: 10}, {name: 'ly', age: 20} ] const fd = new FormData() fd.append('address', arr)
正确的传参方式如下
arr.forEach((value, index) => { fd.append(`address[${index}].name`, value.name) fd.append(`address[${index}].age`, value.age) })
如果是字符串或者数字数组
const arr = [1, 2, 3, 4, 5] arr.forEach((value, index) => { fd.append(`address[${index}]`, value) })
Recommend
-
48
FormData对象用以将数据编译成键值对,以便用XMLHttpRequest来发送数据。其主要用于发送表单数据,但亦可用于发送带键数据(keyed data),而独立于表单使用。如果表单enctype属性设为multipart/form-data ,则会使用
-
36
程序员 - @sayitagain - 一直以来有个疑问,之前公司的 ios 开发要求我的接口给出的数组数据不要是对象,说处理不了,不能处理.举例,本人 PHPer,我通常自己用的数组都是带下标转的,例如{ '100':{
-
12
TS 乏型对象数组的多个定义方式 2021.06.02进击的码农 0 47 我打算在一个使用 TS 的项目里面编写一个 Reac...
-
16
by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=3725
-
7
人人网首页拖拽上传详解(HTML5 Drag&Drop、FileReader API、formdata) 浏览:1044次 出处信息 早在公元2011...
-
5
HTTP content-typeContent-Type(内容类型),一般是指网页中存在的 Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是...
-
10
In this example, we will learn how to upload files with React Hook Form, which is very preferred for managing forms with React. We will use
-
2
一、typeof 不能判断变量是否为数组 var arr = [1 ,2, 3, 4]; console.log(typeof arr); // ObjectJavaScript 二、通过 instanceof 来识别 instanceo...
-
9
Browsers, JSON, and FormData 2022-11-09 Jeremy wrote about w...
-
8
How to Send FormData Objects with Ajax-requests in jQuery ?In this article, we will see how can we send formData objects with
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK