zoukankan      html  css  js  c++  java
  • 微信小程序-wx.request

    微信在请求数据时提供wx.request(funciton)的方式获取数据

    wx.request({
      url: 'test.php', //仅为示例,并非真实的接口地址
      data: {
         x: '' ,
         y: ''
      },
      header: {
          'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res.data)
      }
    })

    其中的urlheadersuccessfail以及complete和普通的http请求是一样

    参数和函数介绍看微信小程序开发api文档,这里不做详解

    谢了一个封装好的回调函数

    供以后用到时可以拿来用

    /**
     * 封转wx.request的post提交请求方式,通过回调函数处理相关数据传递
     * @url:请求地址
     * @postData:请求参数
     * @doSuccess:请求成功回调函数
     * @doFail:请求失败回调函数
     * @doComlete:请求时执行函数
     */
    function rewriteWXRequest(url,postData,doSuccess,doFail,doComplete){
      //console.log(url);
       wx.request({
        url: url,
        data:postData,
        method: 'POST', 
        success: function(res){
         if(typeof doSuccess == "function"){
           doSuccess(res);
         }
        },
        fail: function() {
         if(typeof doFail == "function"){
           doFail();
         }
        },
        complete: function() {
         if(typeof doComplete == "function"){
           doComplete();
         }
        }
       });
    }

     微信其他相关上传,下载等问题:http://www.cnblogs.com/dragondean/p/5921088.html

  • 相关阅读:
    SQLserver 逗号隔开字段分开
    css实现鼠标移动到div,改变另一个div 样式
    selenium账号密码模拟登陆豆瓣
    HTML+CSS基础
    Nginx 报错 413 Request Entity Too Large 的解决方法
    Nginx 报错 504 Gateway Time-out 的解决方法
    Object定时器
    Object标签遮挡
    winRAR打包EXE
    jqGrid API
  • 原文地址:https://www.cnblogs.com/hwaggLee/p/6279066.html
Copyright © 2011-2022 走看看