微信小程序传值到 PHP 后台

wxml文件

  <view >{{id}}</view>
 
js文件
Page({

  data: {
    id:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://localhost:8080/phpclass/QM/C1/PHP/One/2/4.php', 
      data: {
       id:'a',
     
      },
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success (res) {
        console.log(res.data)
      }
    })


  },

}) 
 
 
 
 
PHP文件


<?php

 

$name1 = $_POST['id'];


echo $name1;

 

?>

 

 

输出结果为a

 

 

 

 

 

 

 

 

 

 
posted @ 2020-07-14 13:58  2538  阅读(681)  评论(0编辑  收藏  举报