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)
          }
        })
      }
  • 相关阅读:
    libiconv2.dll
    windows下安装,配置gcc编译器
    STM32之DMA
    keilkill.bat
    STM32之系统滴答定时器
    STM32库函数开发使用总结
    STM32之串口通信
    yocto系统介绍
    fork子进程僵尸问题及解决方案
    shell实现的守护进程
  • 原文地址:https://www.cnblogs.com/baohanblog/p/12465237.html
Copyright © 2011-2022 走看看