• 微信小程序发起请求wx.request


    wx.request相当于发送ajax请求

    参数

    属性类型默认值必填说明
    url string   开发者服务器接口地址
    data string/object/ArrayBuffer   请求的参数
    header Object   设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json
    method string GET HTTP 请求方法
    dataType string json 返回的数据格式
    responseType string text 响应的数据类型
    success function   接口调用成功的回调函数
    fail function   接口调用失败的回调函数
    complete function   接口调用结束的回调函数(调用成功、失败都会执行

    object.success 回调函数

    参数

    Object res

    属性类型说明
    data string/Object/Arraybuffer 开发者服务器返回的数据
    statusCode number 开发者服务器返回的 HTTP 状态码
    header Object 开发者服务器返回的 HTTP Response Header

    wxml

     <button bindtap="qing">请求</button>

    js

    qing:function(){
        wx.request({
          url: 'http://127.0.0.1:8000/test/', //路由
          data:{   //数据
            "name":"egon"
          },
          method:"POST",//请求方法
          header:{ //请求头
            "content-type":"application/json"
          },
          success(e){ //回调
              //e为后台返回的值
            console.log(e.data)
          }
        })
      }
  • 相关阅读:
    理解SetCapture、ReleaseCapture、GetCapture(控制了消息发往哪个窗口,是理解消息的关键)
    Javascript 的addEventListener()及attachEvent()区别分析
    鼠标拖拽
    鼠标右键菜单
    keydown
    一串跟随鼠标的DIV
    event对象和事件冒泡
    发表说说
    文档流
    CSS3 @keyframes 规则
  • 原文地址:https://www.cnblogs.com/baohanblog/p/12465237.html
Copyright © 2020-2023  润新知