赞
踩
wx.request:发起 HTTPS 网络请求
比较常用的就是GET/POST,两者之间的区别在于
1、method不同:一个method: 'POST',一个method: 'GET';
2、当method为GET时,header为默认值{"Content-Type": 'application/json'},当method为POST时,header为{"Content-Type": "application/x-www-form-urlencoded"}
index.js示例:
- wx.request({
- url: 'https://XXXXXXXXXXXXXXXXX/add_cart.html',
- data: {
- code: code,
- quan: quan,
- id: id,
- },
- header: {
- // 'content-type': 'application/json' // 默认值
- "Content-Type": "application/x-www-form-urlencoded" //用于post
- },
- method: 'POST',
- success: function (res) {
- console.log("res", res);
- },
- fail: function (res) { },
- complete: function (res) { },
- })
php后端示例:(以Thinkphp3.2为例)
- //post
- $data = $_POST;
- $code = $data['code'];
- //get
- $code = I("get.code");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。