微信小程序get和post的区别
如果你要提交一篇文章,肯定只能用post,因为数据量太大,get请求类似浏览器url请求,你把一篇文章放到url里面肯定请求不过去,如果你只是个简单的传id或者比较少的参数可以用get,还有就是有密码输入建议用post,post请求参数不会以明文显示在url上
封装了一个wxrequest.js 文件
request请求封装
只用POST,只封装了POST
var apiurl = "xxxxx";
function http_post(controller,data,cb){
wx.request({
url:apiurl+controller,
data:data,
method:'post',
header:{'Content-Type':'application/x-www-form-urlencoded'},
success:function(res){
return typeof cb == "function" && cb(res.data)
},
fail:function(res){
return typeof cb == "function" && cb(false)
}
})
}
module.exports = {
http_post:http_post,//post请求
}
前端js使用
var wxq = require('../../utils/wxrequest.js');
wxq.http_post('这里是控制器/方法',data,function(res){
console.info('回调',res)
})