案例:微信小程序$_POST方式传值
本案例微信小程序$_POST方式传值,后端采用PHP语言。
代码文件
总共有三个文件:
- index.wxml
- index.js
- info.php
index.wxml
文件:
<view class="page">
<view>
<button bindtap="newBtnDown">PHP信息测试</button>
</view>
</view>
index.js
文件:
Page({
newBtnDown() {
wx.request({
url: 'https://wx.slab.ac.cn/test.php',
data: {
userName: JSON.stringify('Administrator'),
passWord: JSON.stringify('123456'),
},
method: 'POST',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function(res) {
console.log(res.data)
wx.showModal({
title: '提示',
content: res.data,
})
},
fail: function(res) {
wx.showModal({
title: '提示',
content: res.data,
})
}
})
},
});
info.php
文件:
<?php
$userName=$_POST["userName"];
$passWord=$_POST["passWord"];
$dateTime=date("Y/m/d H:i:s");
echo "测试时间:".$userName.$passWord.$dateTime;
?>
效果展示
点击按钮显示数据如下:
图1. 数据显示效果
相关文章
作者:戴翔
电子邮箱:[email protected]
简介:中华人民共和国公民,中国共青团员,****博客专家,秦淮区疾控中心托管社会公益组织指南针工作室志愿者,创业公司研发中心负责人,在校大学生。