First write a background data interface, the address is: http://localhost/weicms/index...
Then use wx.request to call the address of the background data interface
Sample code
1 wx.request({ 2 url: 'http://localhost/weicms/index.php?s =/addon/Cms/Cms/getList', 3 data: { 4 x: '', 5 y: '' 6 }, 7 header: { 8 'content-type': 'application/json'// 默认值 9 }, 10 success (res) { 11 console.log(res.data) 12 } 13 })
Run the code, the effect is as follows:
From the picture above, you can see that the page is blank and no data is obtained. , and the console reports an error (request legal domain name verification error; http://localhost is not in the following request legal domain name list)
Why does this error occur?
Open the development document of wx.request network request and you can see
The red box in the screenshot above is the problem (mini program server domain name configuration IP address and localhost cannot be used). The URL address requested by wx.request in the sample code contains localhost, so an error occurs.
But in general, during the development process, you must first develop and debug locally. If the IP address and localhos cannot be used, how to obtain data during local development and debugging? Is there any way to shield this error during local development and debugging?
The answer is yes. The development documentation points out that domain name verification can be skipped, as shown below:
Where exactly do I turn on the option of not verifying the domain name? In the WeChat developer tools, after clicking Details, select Do not verify legal domain names, as shown in the following figure:
At this time, after running the code again, the effect is as follows:
You can see from the above picture that the data has been successfully obtained, and the control has not reported an error. It just prompts: Close the legal domain name, web-view (business domain name), and TLS version in the configuration. And HTTPS certificate check
Recommended tutorial: "WeChat Mini Program"
The above is the detailed content of WeChat applet wx.request request data error. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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