uniapp表单上传到后端
时间: 2023-09-04 11:13:28 浏览: 46
Uniapp表单数据可以通过以下几种方式上传到后端服务器:
1. 使用uni.request() API发送POST请求。
示例代码:
```
uni.request({
url: 'http://your-backend-server-url',
method: 'POST',
data: {
name: 'John',
age: 28,
email: 'john@example.com'
},
success: function(res) {
console.log('Upload success:', res)
},
fail: function(err) {
console.log('Upload fail:', err)
}
})
```
2. 使用uni.uploadFile() API上传文件。
示例代码:
```
uni.uploadFile({
url: 'http://your-backend-server-url',
filePath: 'path/to/file',
name: 'file',
formData: {
name: 'John',
age: 28,
email: 'john@example.com'
},
success: function(res) {
console.log('Upload success:', res)
},
fail: function(err) {
console.log('Upload fail:', err)
}
})
```
在以上示例中,formData参数可以用来传递除文件之外的表单数据。
注意:以上代码仅为示例代码,实际应用中需要根据具体情况进行修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)