您的位置:首页 > 移动开发 > 微信开发

小程序 后台数据请求

2017-04-27 10:39 141 查看
wx.request({

  url: 'test.php', //仅为示例,并非真实的接口地址

  data: {

     x: '' ,

     y: ''

  },

  header: {

      'content-type': 'application/json'

  },

  success: function(res) {

    console.log(res.data)

  }

})


data 数据说明 最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下:

对于 header['content-type'] 为 'application/json' 的数据,会对数据进行 JSON 序列化
对于 header['content-type'] 为 'application/x-www-form-urlencoded' 的数据,会将数据转换成 query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐