Home >WeChat Applet >Mini Program Development >WeChat applet wx.request realizes background data interaction function analysis
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'); } })
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'); } })
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="http://www.php.cn/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!