Home > WeChat Applet > Mini Program Development > Network requests in WeChat applet (post request and get request)

Network requests in WeChat applet (post request and get request)

不言
Release: 2018-06-27 11:38:43
Original
4639 people have browsed it

This article mainly introduces the relevant information about WeChat Mini Program network requests (post requests, get requests). Friends in need can refer to

WeChat Mini Program Network Requests

1.Post request:

onLoad: function() { 
  that = this; 
  wx.request( { 
   url: "url", 
   header: { 
    "Content-Type": "application/x-www-form-urlencoded" 
   }, 
   method: "POST", 
   data: {}, 
   complete: function( res ) { 
    console.log(res.data)
    }); 
    if( res == null || res.data == null ) { 
     console.error( '网络请求失败' ); 
     return; 
    } 
   } 
  }) 
 },
Copy after login

2.GET request

onLoad: function () {
  console.log('onLoad')
  var that = this
   wx.request({
   url: 'http://json.bmbstack.com/cinemaList',
   data: {},
   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    header: {
   'Accept': 'application/json' 
    }, // 设置请求的 header
   success: function(res){
    that.data.items= res.data
   },
   fail: function() {
    // fail
   },
   complete: function() {
    // complete
   }
  })
 }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to WeChat applet request request backend interface php

WeChat applet GET request introduce

The above is the detailed content of Network requests in WeChat applet (post request and get request). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template