WeChat applet development--3.1wx.request

wx.request is to send an http request to the specified domain name, and the specified domain name needs to be added to the WeChat applet management background ( only https domain names can be added to the WeChat applet background, perhaps because WeChat officials think this will be more secure).

wx.request({//不传递参数
     url : 'https://...',
      success(res){
        console.log(res.data)//返回数据
      },
      complete(res){
      }
})
wx.request({//传递参数
     url : 'https://...',
     data:{
       'id':this.data.id
     }
      success(res){
      },
      complete(res){
      }
})

1.success(), the callback method for successful request. The success of the request here refers to the time from the request to the server completing the response and returning the relevant data! In other words, as long as the server responds, the request is considered completed, including 404 not found, 500 server internal error and other responses, so developers need to make their own judgments.

2.fail(), callback method for request failure. The request failure here refers to situations other than success().

3.complete(), this callback function will be called whether the request succeeds or fails.

Res.data contains returned parameters, which can be rendered into the page.

Guess you like

Origin blog.csdn.net/weixin_46479909/article/details/131680936