This article mainly introduces detailed information about the small program network request (GET request). If you need it, refer to the next article. it mainly introduces the small program network request (GET request) for more information, see
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 following is the GET request code:
// 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 ,})}})}})
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!
The above is a detailed description of the small program network request (GET request). For more information, see other related articles in the first PHP community!