網站首頁 編程語言 正文
????????微信小程序開發中網絡請求必不可少.GET .POST請求是最常用的.GET請求,POST請求的時候有好幾個坑.我已經為大家填好了.
1.? 'Content-Type': 'application/json'用在get請求中沒問題.
????????之前的.GET 請求都是如下這樣寫:(給大家舉個例子)
wx.request({
url: url,
data: {
teacherid: teacherid
},
header: {
'content-type': 'application/json'
},
success: (res) => {
// console.log(res.data);
this.setData({
testpaper: res.data.testpaper,
teacher : res.data.teacher
});
}
})
但是post方式提交的話就有所改變了,給大家列出以下幾點注意事項:1.? 'Content-Type': 'application/json'用在get請求中沒問題.
POST請求就不好使了.需要改成 : ?"Content-Type": "application/x-www-form-urlencoded"
2. 加上 method: "POST"
3.?data: { answer : {?"a":10,"b":8,"c":6 } } 寫成json格式這樣也是請求不到數據的.需要轉格式.
這里我用JSON.Stringify() 將json對象轉換成json字符串格式
部分代碼分享給大家,這里answer與student 都是json對象格式需要轉換
wx.request({
url : "https://www.",
method: "POST",
data: {
answer : JSON.stringify(this.data.answer),
score : _score,
pjid : this.data.pj.pjid,
testpaperid : this.data.pj.testpaperid,
student : JSON.stringify(this.data.student),
message : this.data.message
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function (res) {
console.log(res.data);
wx.navigateBack({
delta: 1 //小程序關閉當前頁面返回上一頁面
})
wx.showToast({
title: '評教成功!',
icon: 'success',
duration: 2000
})
},
})
如有問題,歡迎留言,與大家共同探討與學習?。。?/p>
原文鏈接:https://blog.csdn.net/lff1123/article/details/80254282
相關推薦
- 2022-08-18 C語言系統日期和時間實例詳解_C 語言
- 2022-07-15 SQL?Server中的排名函數與分析函數詳解_MsSql
- 2022-09-18 C++如何實現二叉樹鏈表_C 語言
- 2022-04-08 iOS實現簡單計算器功能_IOS
- 2022-04-24 一起來學習C語言的字符串轉換函數_C 語言
- 2022-09-18 Rust實現grep命令行工具的方法_相關技巧
- 2022-10-24 利用Pandas求兩個dataframe差集的過程詳解_python
- 2023-11-11 【數據處理】Python matplotlib繪制雙柱狀圖以及繪制堆積柱狀圖——保姆級教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支