search
HomeWeChat AppletMini Program DevelopmentWeChat applet development: How to implement network requests (GET requests)

The technological changes of the Internet are really turbulent and ever-changing. Fortunately, everything remains unchanged. With the advent of mini programs on January 9, we IT professionals can only keep learning. Internet web development will inevitably use network get requests, so how to implement network requests in WeChat applet development? Today I will talk about the simplest request. I will try to upload, download, and Socket later.

Notes on WeChat applet requests:
1. A WeChat applet can only have 5 network request connections at the same time.
This rule should be formulated by WeChat to ensure user experience. After all, it is a mini program.
2.wx.request(OBJECT) Parameter description:

 微信小程序开发:如何实现网络请求(GET请求)

WeChat The applet supports GET, POST and other requests. It can be set using method.
The following is the code for the GET request:

<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>

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

 微信小程序开发:如何实现网络请求(GET请求)

You don’t need to do the parsing of json yourself. When I was doing Android, I had to use gson or fastjson to parse json. WeChat has indeed saved a lot of development costs for our developers. Is this a good thing or a bad thing for developers? .

For more WeChat applet development: How to implement network requests (GET requests), please pay attention to the PHP Chinese website for related articles!


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software