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
});
}
})
有以下几点注意事项:
'Content-Type':'application/json'
'Content-Type':'application/x-www-form-urlencoded'
method:'POST'
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
})
},
})