博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序 wx.request
阅读量:4582 次
发布时间:2019-06-09

本文共 1309 字,大约阅读时间需要 4 分钟。

wx.request({
  url: 'https://hanwslh5.qcloud.la/weapp/HelloWorld',

  对于 GET 方法的数据,会将数据转换成 query string(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...

  // get的方法
  // data:{
    // "p1": 1,
    // "p2": 'p2'
  // },
  // method: 'GET',
 
  

  对于 POST 方法且 header['content-type'] 为 application/x-www-form-urlencoded 的数据,会将数据转  querystring (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)

  //post的方法urlencode
  // data:{
    // "p1": 1,
    // "p2": 'p2'
  // },
  // header:{
    // 'content-type': 'application/x-www-form-urlencoded'
  // },
  // method: 'POST',

  

  对于 POST 方法且 header['content-type'] 为 application/json 的数据,会对数据进行 JSON 序列化

  //post的方法 Json
  data:{
    "p1": 1,
    "p2": 'p2'
  },
  header:{
    'content-type': 'application/json'
  },
  method: 'POST',
  success: function(res){
    console.log(1111)
    console.log("-----in success-----")
    console.log(res)
    console.log(res.statusCode)
    if (res.StatusCode==200){
      console.log(res.statusCode)
    }
  },
  fail: function(res){
    console.log("-----in fail-----")
    console.log(res)
  },
  complete: function(res){
    console.log("-----in complete-----")
    console.log(res)
  }
})

 

转载于:https://www.cnblogs.com/sklhtml/p/9718188.html

你可能感兴趣的文章
各个控件说明
查看>>
鼠标事件(jQuery)
查看>>
delete指针时coredump的分析之旅
查看>>
openoffice+pdf2swf+FlexPaper在线显示office和pdf
查看>>
24-React Components组件
查看>>
[BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】
查看>>
[BZOJ - 2631] tree 【LCT】
查看>>
ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程...
查看>>
JS实现数组排序:升序和降序
查看>>
怎样写具体设计文档
查看>>
CAShapeLayer
查看>>
ACM_夏天到了,又到了出游的季节
查看>>
【转载】HTTP 错误 500.19 - Internal Server Error
查看>>
2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo
查看>>
SQL Server 存储图片
查看>>
php特级课---4、网站服务监控(常用网站服务监控软件有哪些)
查看>>
ubuntu14.04 boost 1.58.0 安裝
查看>>
漏洞基本概念
查看>>
直角三角形 (Standard IO)
查看>>
web 12
查看>>