欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  微信小程序

微信小程序中的网络请求(post请求和get请求)

程序员文章站 2022-04-08 18:10:18
...
这篇文章主要介绍了微信小程序 网络请求(post请求,get请求)的相关资料,需要的朋友可以参考下

微信小程序 网络请求

1.post请求:

onLoad: function() { 
  that = this; 
  wx.request( { 
   url: "url", 
   header: { 
    "Content-Type": "application/x-www-form-urlencoded" 
   }, 
   method: "POST", 
   data: {}, 
   complete: function( res ) { 
    console.log(res.data)
    }); 
    if( res == null || res.data == null ) { 
     console.error( '网络请求失败' ); 
     return; 
    } 
   } 
  }) 
 },

2.GET请求

onLoad: function () {
  console.log('onLoad')
  var that = this
   wx.request({
   url: 'http://json.bmbstack.com/cinemaList',
   data: {},
   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    header: {
   'Accept': 'application/json' 
    }, // 设置请求的 header
   success: function(res){
    that.data.items= res.data
   },
   fail: function() {
    // fail
   },
   complete: function() {
    // complete
   }
  })
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

微信小程序request请求后台接口php的介绍

微信小程序的GET请求的介绍

以上就是微信小程序中的网络请求(post请求和get请求)的详细内容,更多请关注其它相关文章!