[关闭]
@Perfect-Demo 2018-03-17T12:46:47.000000Z 字数 621 阅读 726

微信小程序前端POST 和 GET请求

微信小程序


POST请求:

  1. onLoad: function() {
  2. that = this;
  3. wx.request( {
  4. url: "url",
  5. header: {
  6. "Content-Type": "application/x-www-form-urlencoded"
  7. },
  8. method: "POST",
  9. data: {},
  10. complete: function( res ) {
  11. console.log(res.data)
  12. });
  13. if( res == null || res.data == null ) {
  14. console.error( '网络请求失败' );
  15. return;
  16. }
  17. }
  18. })
  19. },

GET请求:

  1. onLoad: function () {
  2. console.log('onLoad')
  3. var that = this
  4. wx.request({
  5. url: 'http://json.bmbstack.com/cinemaList',
  6. data: {},
  7. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  8. header: {
  9. 'Accept': 'application/json'
  10. }, // 设置请求的 header
  11. success: function(res){
  12. that.data.items= res.data
  13. },
  14. fail: function() {
  15. // fail
  16. },
  17. complete: function() {
  18. // complete
  19. }
  20. })
  21. }

参考脚本之家,侵删。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注