Network requests (GET requests) of applets are described in detail.
Applet network request GET
Network requests are essential in applet development. Today we will talk about the simplest requests. We will try to upload and download these requests in the future.
1. A small program can have only five network request connections at the same time.
This rule should be made to ensure the user experience. After all, it is a small program.
2. wx. request (OBJECT) parameter description:
The applet supports GET, POST, and other requests. You can set it using method.
The following is the GET Request Code:
<Span style = "font-size: 18px;"> // rate. js // obtain the application instance var app = getApp () Page ({data: {code: 'use', currencyF_Name: '', currencyT_Name:'', currencyF :'', currencyT: '', currencyFD: 1, exchange: 0, result: 0, updateTime:'',}, onLoad: function (options) {var that = this; // obtain the wx exchange rate. request ({url: "http://op.juhe.cn/onebox/exchange/currency? Key = My 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>
In the above Code, you only need to provide the URL. the onLoad function is started during page initialization, wx. res of success in request. data is the data obtained from the background.
The json data format obtained is as follows.
Json parsing does not need to be done by myself. I still need to use gson or fastjson to parse json when doing Android. This solves a lot of trouble for us.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!