Due to a small program initiating a network request through Wx.request
Document Address
Https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-request.html
Accustomed to use Ajax, then the (wx.request) package 1, the new file Http.js
/* Used Ajax, then the (wx.request) encapsulation, call Mode 1, first introduced: Const HTTP = require ('. /.. /js/http.js ') 2, how to use: Http.post or HTTP.GET3, params parameter format such as: {start:1, count:4}*//* Official document https://mp.weixin.qq.com/debug/ Wxadoc/dev/api/network-request.html*/module.exports = { get (Apiurl, yes, error) { wx.request ({ URL: Apiurl, header: {' Content-type ': ' JSON '}, Success:yes, fail:error }) }, post (Apiurl, Params, yes, error) { wx.request ({ url:apiurl, data:params, header: {' Content-type ': ' JSON '},< C13/>success:yes, fail:error }) }}
2. Page Call mode
/** * Life cycle Function--Listen page load */ onload:function (options) { Const HTTP = require ('). /.. /js/http.js ')//introduction of http.js file var params = {start:1, count:4};//Parameter http.post ("Https://api.douban.com/v2/movie /coming_soon ", {start:1,count:4}, function (res) { Console.log (" return result = "+json.stringify (res.data)); }, Function (e) { console.log ("return error result =" + json.stringify (e));} );
The applet calls the API to return data or submit data