XMLHttpRequest send多个参数

在工作中遇到了如何send多个参数

在最开始之前是这样写的:

var fd = new FormData()
fd.append('file', this.$refs.file.files[0])
this.uploadFileName = this.$refs.file.files[0].name
var xhr = new XMLHttpRequest()
var thisInstance = this;
xhr.open('POST', api, true)
xhr.send(fd)

我还想再send一个int值去判断 是来自不同地方的api的调用,来自四面八方的send,得让后台知道是哪些个四面和八方吧,我试过的写法是:
xhr.send(fd,0);
xhr.send(fd+0);
xhr.send(fd&0);

都不行!正确的写法是:

var fd = new FormData()
fd.append('file', this.$refs.file.files[0])
fd.append('intval',0)//加了这一句
this.uploadFileName = this.$refs.file.files[0].name
var xhr = new XMLHttpRequest()
var thisInstance = this
xhr.open('POST', api, true)
xhr.send(fd)

原理是什么呢?其实就是我send的是一个大的数组 或者理解为一个表格,至于你要多少变量,你想要多少参数,就往这个表格里面push也就是append 就行了。
ok,解决啦!

参照:https://blog.csdn.net/yiboo/article/details/8816736

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值