mathhater 2022-09-19 16:30 采纳率: 64.3%
浏览 72
已结题

微信小程序发起对服务器发起post请求中,请求体data数据中如何传递复选框的值

本人在服务器端有一个.php脚本
该脚本中有个复选框用来采集客户端的复选项如下

<input class="form-check-input" id='s1' type='checkbox' name='check[]' value=0 >
                 <label class="form-check-label" for="s2">140/120:</label><input class="form-check-input"id='s2'type='checkbox' name='check[]' value=2 >
                 <label class="form-check-label" for="s3">190/145:</label><input class="form-check-input"id='s3'type='checkbox' name='check[]' checked='checked' value=4 >
                <label class="form-check-label" for="s4">200/170:</label><input class="form-check-input"id='s4'type='checkbox' name='check[]' value=6 >
                <label class="form-check-label" for="s5">207/112:</label><input class="form-check-input"id='s5'type='checkbox' name='check[]' value=9 >
                <label class="form-check-label" for="s6">215/140:</label><input class="form-check-input"id='s6'type='checkbox' name='check[]' value=10 >
                <label class="form-check-label" for="s7">220/170:</label><input class="form-check-input"id='s7'type='checkbox' name='check[]' value=8 >
                <label class="form-check-label" for="s8">230/130:</label><input class="form-check-input"id='s8'type='checkbox' name='check[]' value=1 >
                <label class="form-check-label" for="s9">240/180:</label><input class="form-check-input"id='s9'type='checkbox' name='check[]' value=3 >
                 <label class="form-check-label" for="s10">300/200:</label><input class="form-check-input"id='s10'type='checkbox' name='check[]' value=5 >
                <label class="form-check-label" for="s11">318/140:</label><input class="form-check-input"id='s11'type='checkbox' name='check[]' value=7 >

当用户提交表达后,服务器端另外一个逻辑处理脚本接收复选框提交上来的值

<?php 
if($_POST)
$value=$_POST['check'];
?>

我现在想把这两个脚本接口开放给微信小程序
在微信小程序对应的页面.js脚本中有这么一个处理函数

getinfo(){

  wx.request({
          url: 'https://www.examples.com/moldarrange/moldarrange.php', // 仅为示例,并非真实的接口地址
          method: 'post',
          data: {
            moldx:1,
            moldy:1,
            productx:300,
            producty:200,
            gap:80,
            water:0,
            check[]:4,
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded' // 默认值
          },
          success(res) {
        console.log(res.data)
          }
        })
}

小程序data对象里不知道如何填写复选框check[]用来给服务器上的脚本moldarrange.php来发送post请求
试过很多格式如 check[]:2,3,4 check:[2,3,4] check%5B%5D:2,3,4 等等,都报错,服务器脚本无法得到正确的复选框值,请教各位如何填写

  • 写回答

3条回答 默认 最新

  • 一把编程的菜刀 2022-09-19 16:55
    关注

    你应该转成josn字符串: check:JSON.stringify([1,2,3]),php再转成数组就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月27日
  • 已采纳回答 9月19日
  • 创建了问题 9月19日

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加