当前位置:网站首页>PHP receiving and sending data

PHP receiving and sending data

2022-06-23 13:51:00 qq_ forty-five million nine hundred and eleven thousand five hu

Write it at the front : Before reading this article , Hope readers have some php The basis of , You also need to know some knowledge about building websites

The client is usually through url Go to the server , After receiving the request from the client, the server returns the data required by the client to the client , There are naturally two problems :

1、 How the server receives requests sent by clients

Build a php file , Name it welcome.php, Write content in it

 welcome  <?php echo $_REQUEST["fname"]; ?>!<br>
 Your age is  <?php echo $_REQUEST["age"]; ?>   year .

Create a folder under the root directory of the website as minipro, Put this file in this folder
 Insert picture description here
Then you access the connection through the browser http://127.0.0.1/minipro/welcome.php?fname=ericzeng&age=2
give the result as follows :
 Insert picture description here
At this point, the data receiving is realized

2、 How the server returns data to the client , How the client receives

I used to be confused here , Later, it was found that only one was needed echo sufficient , See the following example :
We use the wechat applet to send requests to the local server ( It needs to be set up , Set up -> Project settings -> Check not verifying legal domain name https What? , Otherwise, a request can be made to the local server )
 Insert picture description here

The applet file information is as follows :
index.js

Page({
    
  data: {
    
    t:"haode"
  },
  onLoad: function () {
    
  this.setData({
    t:"hello world!"});
  wx.request(
    {
    
      url:"http://127.0.0.1/minipro/welcome.php?fname=ericzeng&age=2",
      headers:{
    
        'content-type':'application/json'
      },
      method:'GET',
      success:res=>{
    
        this.setData({
    
          t:res.data
        })
      }
    }
  );
}
})

index.wxml

<view>
    <view>{
    {
    t}}</view>
</view>

We still visit the previous link , You will find that the data on the web page appears on the applet page , Just process the data format locally ok 了 , Of course, the data we usually use json Format to transmit , stay php Use in json_encode() Method can convert data to json, Use to search for more specific content .

 Insert picture description here

原网站

版权声明
本文为[qq_ forty-five million nine hundred and eleven thousand five hu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231312151140.html