微信小程序 GET请求 与POST 请求

微信小程序get和post的区别

如果你要提交一篇文章,肯定只能用post,因为数据量太大,get请求类似浏览器url请求,你把一篇文章放到url里面肯定请求不过去,如果你只是个简单的传id或者比较少的参数可以用get,还有就是有密码输入建议用post,post请求参数不会以明文显示在url上

post get请求 点这里

封装了一个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)
	})
发布了34 篇原创文章 · 获赞 1 · 访问量 7421

猜你喜欢

转载自blog.csdn.net/chihouzi/article/details/99670863