微信小程式wx.request使用post方式傳參
阿新 • • 發佈:2019-01-08
需要注意的是method是get方式的時候,header為{"Content-Type": 'application/json'},當method為post時,header為{"Content-Type": "application/x-www-form-urlencoded"}
post方式傳遞的引數需要轉換
1。js中
var util=require('../../utils/util.js');page({
loginSubmit:function(e){ console.log(e.detail.value.username), console.log(util.formatTime), wx.request({ url: 'http://127.0.01:8000/runxiang_yiyao/Mobile/Index/login'header: { "Content-Type": "application/x-www-form-urlencoded" }, success: function (res) { console.log(util.formatTime) // console.log(res) } }) }
})
2. 在util中定義函式json2Form
function json2Form(json) { var