zoukankan      html  css  js  c++  java
  • 微信小程序发起请求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)
          }
        })
      }
  • 相关阅读:
    最小的k个数
    复杂链表的复制
    二叉树中和为某一值的路径
    二叉搜索树的后序遍历序列
    STL之Deque容器
    STL之迭代器
    STL之Vector容器
    STL之string
    STL(标准模板库)基本概念
    文件I/O
  • 原文地址:https://www.cnblogs.com/baohanblog/p/12465237.html
Copyright © 2011-2022 走看看