WeChat applet wx.request realizes background data interaction function analysis

小云云
Release: 2018-05-17 16:42:23
Original
4718 people have browsed it

This article mainly introduces the WeChat applet wx.request to implement the background data interaction function, and analyzes the problems and related solutions encountered by the WeChat applet wx.request in the background data interaction process. Friends in need can refer to the following

Record the problems encountered by the WeChat applet wx.request API when interacting with the background.

1. According to the information, complete the first step and send the request. The code is as follows:

wx.request({
     url: 'https://localhost:8443/xiaochengxu/addBill.do',
     data: e.detail.value,
     method: 'POST',
     success:function(res) {
       console.log('submit success');
     },
     fail:function(res){
       console.log('submit fail');
     },
     complete:function(res){
       console.log('submit complete');
     }
})
Copy after login

The request was successfully received in the background, and submit success and submit were also printed on the console. complete, however, the background request did not receive the data. When debugging was turned on, it was found that the data was in the request payload, so neither the springmvc mapped bean nor req.getParameter could get the parameters in the background.

To put it simply, header: {'content-type': 'application/x-www-form-urlencoded'} is added, and the data is successfully obtained in the background.

So far, the code is as follows:

wx.request({
     url: 'https://localhost:8443/xiaochengxu/addBill.do',
     data: e.detail.value,
     method: 'POST',
     header: {'content-type': 'application/x-www-form-urlencoded'},
     success:function(res) {
       console.log('submit success');
     },
     fail:function(res){
       console.log('submit fail');
     },
     complete:function(res){
       console.log('submit complete');
     }
})
Copy after login

2. Receive request return data

This step is not a big problem. I returned it in json format. If you just follow the console.log(res.data) written on the official website, Object will be printed on the console, just bring the parameter name, such as res.data.code

Related recommendations:

##WeChat Mini Program page jump function<a href="//m.sbmmt.com/xiaochengxu-382229.html" target="_self"></a>

WeChat Mini Program Complete example of form verification function

WeChat applet implements method of dynamically changing the width and height of view label

The above is the detailed content of WeChat applet wx.request realizes background data interaction function analysis. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!