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)
          }
        })
      }
  • 相关阅读:
    JS URL传中文参数引发的乱码问题
    git (转载)
    php webservice
    php date之间的相互转换
    在图片上加字符-base64转图片-图片转base64
    转:微软面试一百题
    2014-8-17 note
    some base knowledge
    introduction
    Centos6.6 编译安装nginx
  • 原文地址:https://www.cnblogs.com/baohanblog/p/12465237.html
Copyright © 2011-2022 走看看