在工作中遇到了如何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