Home > WeChat Applet > Mini Program Development > Detailed description of WeChat applet network request (GET request)

Detailed description of WeChat applet network request (GET request)

高洛峰
Release: 2017-03-13 11:27:38
Original
3149 people have browsed it

This article mainly introduces the relevant information about the detailed description of the WeChat Mini Program network request (GET request). Friends in need can refer to

WeChat Mini Program Network Request GET

Network requests are essential in the development of WeChat mini programs. Today we will talk about the simplest requests. We will try uploading, downloading, and Socket later.

1. A WeChat mini program, only There can be 5 network request connections.

This rule should be formulated by WeChat to ensure user experience. After all, it is a mini program.

2.wx.request(OBJECT) Parameters Note:

Detailed description of WeChat applet network request (GET request)

WeChat applet supports GET, POST and other requests. You can set it with method.

The following is GET Requested code:

<span style="font-size:18px;">//rate.js 
//获取应用实例 
var app = getApp() 
Page( { 
 data: { 
  code: &#39;USD&#39;, 
  currencyF_Name: &#39;&#39;, 
  currencyT_Name: &#39;&#39;, 
  currencyF: &#39;&#39;, 
  currencyT: &#39;&#39;, 
  currencyFD: 1, 
  exchange: 0, 
  result: 0, 
  updateTime: &#39;&#39;, 
 }, 
 onLoad: function( options ) { 
  var that = this; 
   //获取汇率 
   wx.request( { 
    url: "http://op.juhe.cn/onebox/exchange/currency?key=我的appkey&from=CNY&to="+code, 
    success: function( res ) { 
     that.setData( { 
      currencyF_Name: res.data.result[0].currencyF_Name, 
      currencyT_Name: res.data.result[0].currencyT_Name, 
      currencyF: res.data.result[0].currencyF, 
      currencyT: res.data.result[0].currencyT, 
      currencyFD: res.data.result[0].currencyFD, 
      exchange: res.data.result[0].exchange, 
      result: res.data.result[0].result, 
      updateTime: res.data.result[0].updateTime, 
     }) 
    } 
   }) 
 } 
})</span>
Copy after login

In the above code, you only need to give the URL. onLoad function is started when the page is initialized. The res of success in wx.request({}) .data is the data obtained from the background, which needs attention.

The following is the format of the obtained json data.

Detailed description of WeChat applet network request (GET request)

You don’t need to do the parsing of json yourself. When I do Android, I have to use gson or fastjson to parse json. WeChat solves a lot of trouble for us.

Thanks for reading, I hope it can help everyone, thank you for your support of this site!

The above is the detailed content of Detailed description of WeChat applet network request (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