小程序售票---前台购票传输数据到后台生成票

1:页面结构

wxml代码: 用了form表单把要传输的数据 后台接受数据用 name来接受 

<view class="container">
  <template is="head" data="{{title: '售票测试'}}"/>

  <view class="page-body">
     <form catchsubmit="formSubmit" catchreset="formReset">
      <!-- <view class="page-section page-section-gap">
        <view class="page-section-title">switch</view>
        <switch name="switch"/>
      </view> -->

      <view class="page-section page-section-gap">
     
        <view class="page-section-title">radio</view>
        <radio-group name="radio" >
          <label><radio value="0" checked='true'/>单场票(限时)</label>
          <label><radio value="1"/>单场票(不限时)</label>
        </radio-group>
      </view>

   
      <view class="page-section page-section-gap">
        <view class="page-section-title">slider</view>
        <slider value="1" name="slider" show-value min="1" max="5"></slider>
      </view>

     <input value='{{openid}}' name="openid" hidden='true'></input>

      <view class="btn-area">
        <button type="primary"  formType="submit">提交</button>
        <button formType="reset">重选</button>
     
      </view>
      
    </form>
  </view>

js代码:用 formSubmit来传递数据给后台 我的是springboot后台 如果未上传到服务器,url可以用  http://localhost:8080把数据传给后台

后台接收:

 

 
 
Page({
  data: {
    pickerHidden: true,
    chosen: '',
    openid:''
  },
  onLoad: function () {
    this.getOpenid(); }, // 获取用户openid  getOpenid() { let that = this; wx.cloud.callFunction({ name: 'getOpenid', complete: res => { console.log('云函数获取到的openid: ', res.result.openId) var openid = res.result.openId; that.setData({ openid: openid }) } }) }, pickerConfirm: function (e) { this.setData({ pickerHidden: true }) this.setData({ chosen: e.detail.value }) }, pickerCancel: function (e) { this.setData({ pickerHidden: true }) }, pickerShow: function (e) { this.setData({ pickerHidden: false }) }, formSubmit: function (e) { var formData = e.detail.value; wx.request({ url: 'http://xxxx', data: formData, success: function (res) { console.log(res.data), wx.navigateTo({ url: '../mytickets/mytickets?code='+res.data+' ' }) } }) console.log('form发生了submit事件,携带数据为:', e.detail.value) }, formReset: function (e) { console.log('form发生了reset事件,携带数据为:', e.detail.value) this.setData({ chosen: '' }) }, qrcode: function (e) { wx.navigateTo({ url: '../../qrcode/qrcode' }) } })

转载于:https://www.cnblogs.com/a565810497/p/9923033.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值