admin管理员组文章数量:1200394
Here I have this.state.word is boolean type
so value is in true/false
but when I want to try to append this.state.word
it gives me error like this argument type boolean is not assignable to parameter type string | blob
so how to append boolean type values(true/false) in formdata( NOTE :- I want to send in boolean type not in string) ?
handleSendSynopsis() {
const data = new FormData();
data.append('word', this.state.word);
}
Here I have this.state.word is boolean type
so value is in true/false
but when I want to try to append this.state.word
it gives me error like this argument type boolean is not assignable to parameter type string | blob
so how to append boolean type values(true/false) in formdata( NOTE :- I want to send in boolean type not in string) ?
handleSendSynopsis() {
const data = new FormData();
data.append('word', this.state.word);
}
Share
Improve this question
edited Feb 7, 2019 at 7:10
asked Feb 7, 2019 at 7:07
user10950990user10950990
4
|
2 Answers
Reset to default 16use JSON.stringify on the client to send numbers and boolean values, then parse it on the backend
For Example
const form = new FormData;
const data = {
name: 'john doe',
active: true,
count: 42
};
form .append('file', file); // send your file here
form .append('fileProps', JSON.stringify(data));
According to FormData Documentation, FormData.append
accepts only a USVString
or a Blob
. S you will have to convert your data to string and then parse it later on the backend. You can use JSON.stringify
to convert your form object to a string.
本文标签: javascriptHow to append boolean type values in formdataStack Overflow
版权声明:本文标题:javascript - How to append boolean type values in formdata? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738611847a2102675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
String(this.state.word)
– Vaibhav Vishal Commented Feb 7, 2019 at 7:09