小程序--wx.request网络请求

(1)使用wx.request可以发起一个http请求,一个微信小程序被限制为同时只有5个网络请求。

function queryRequest(data){
    
            
  wx.request({
    
    //发起 HTTPS 网络请求        
  url:"https://example.com/api/",//开发者服务器接口地址
  method: 'GET',//HTTP 请求方法
  header: {
    
    'content-type': 'application/json' },// 默认值        
  data:data,//请求的参数        
  success:function(res){
    
    //接口调用成功的回调函数            
    console.log(res.data)        
  },        
  fail:function(err){
    
      //接口调用失败的回调函数            
     console.log(err)        
  }    
})}

对于 header[‘content-type’] 为 ‘application/json’ 的数据,会对数据进行 JSON 序列化

猜你喜欢

转载自blog.csdn.net/huang_jimei/article/details/106376571