1. 程式人生 > >微信小程式開發POST請求

微信小程式開發POST請求

微信小程式開發POST請求

wx.request( {  
      url: "http://op.juhe.cn/onebox/weather/query",  
      header: {  
        "Content-Type": "application/x-www-form-urlencoded"  
      },  
      method: "POST",  
     //data: { cityname: "上海", key: "de" },  
      data: Util.json2Form( { cityname: "上海", key: "fddf" }),  
      complete: function( res ) {  
      }
})
微信小程式示例

wx.request({
  url: 'test.php', //僅為示例,並非真實的介面地址
  data: {
        x: '' , 
        y: ''
   }, 
  header: { 
    'content-type': 'application/json' 
  }, 
  success: function(res) { 
    console.log(res.data) 
  }
})
method: 'POST',
    header:{
      'content-type':'application/x-www-form-urlencoded'
    },
onLoad: function() { 
  that = this; 
  wx.request( { 
   url: "url", 
   header: { 
    "Content-Type": "application/x-www-form-urlencoded" 
   }, 
   method: "POST", 
   data: {}, 
   complete: function( res ) { 
    console.log(res.data)
    }); 
    if( res == null || res.data == null ) { 
     console.error( '網路請求失敗' ); 
     return; 
    } 
   } 
  }) 
 }, 
data: Util.json2Form( { cityname: "北京", key: "1430ec127e097e1113259c5e1be1ba70" }), 
header: {"Content-Type":"application/x-www-form-urlencoded"},
wx.request({
      url : "https://www.",
      method: "POST",
      data: {
        answer : JSON.stringify(this.data.answer),
        pjid : this.data.pj.pjid,
        testpaperid : this.data.pj.testpaperid,
        student : JSON.stringify(this.data.student),
        message : this.data.message
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res.data);
        wx.navigateBack({
          delta: 1  //小程式關閉當前頁面返回上一頁面
        })
      },
    })

在這裡插入圖片描述

<!--pages/anquan/anquan.wxml-->
<view class='bg'>
  <view class='item'>
    身份認證
    <view class='bk'>
      <!-- <textarea class="textarea" placeholder='身份認證' auto-height value='{{detailanquan.idCard}}' maxlength='10'></textarea> -->
      <input name='idCard' class="textarea" placeholder="{{detailanquan.idCard}}" value='{{detailanquan.idCard}}' bindinput="idCard" maxlength='15' auto-height/>

    </view>
    <button class='btn' bindtap='sfrz'>修改</button>
  </view>
  <view class="line"></view>

  <view class='item'>
    登入密碼
    <view class='bk'>
      <!-- <textarea class="textarea" placeholder='登入密碼' auto-height value='{{anquan.password}}' maxlength='100'></textarea> -->
      <input name='password' class="textarea" placeholder="{{anquan.password}}" value='{{anquan.password}}' bindinput="password" maxlength='100' auto-height/>

    </view>
    <button class='btn' bindtap='dlmm'>修改</button>
  </view>
  <view class="line"></view>

  <view class='item'>
    繫結手機
    <view class='bk'>
      <!-- <textarea class="textarea" placeholder='繫結手機' auto-height value='{{anquan.phone}}' maxlength='15'></textarea> -->
      <input name='phone' class="textarea" placeholder="{{anquan.phone}}" value='{{anquan.phone}}' bindinput="phone" maxlength='15' auto-height/>

    </view>
    <button class='btn' bindtap='bdsj'>設定</button>
  </view>
  <view class="line"></view>

  <view class='item'>
    繫結郵箱
    <view class='bk'>
      <!-- <textarea class="textarea" placeholder='繫結郵箱' auto-height value='{{anquan.email}}' maxlength='30'></textarea> -->
      <input name='email' class="textarea" placeholder="{{anquan.email}}" value='{{anquan.email}}' bindinput="email" maxlength='30' auto-height/>

    </view>
    <button class='btn' bindtap='bdyx'>修改</button>
  </view>
  <view class="line"></view>

  <view class='item'>
    微信繫結
    <view class='bk'>
      <!-- <textarea class="textarea" placeholder='微信繫結' auto-height value='{{anquan.wxUnionid}}' maxlength='100'></textarea> -->
      <input name='wxUnionid' class="textarea" placeholder="{{anquan.wxUnionid}}" value='{{anquan.wxUnionid}}' bindinput="wxUnionid" maxlength='100' auto-height/>

    </view>
    <button class='btn' bindtap='wxbd'>修改</button>
  </view>
  <view class="line"></view>
</view>

在這裡插入圖片描述

<view class='bg'>
  <view class='item'>
    當前頭像:
    <open-data type="userAvatarUrl" class='img'></open-data>
  </view>

  <form bindsubmit="formSubmit" bindreset="formReset">
    <view class='item'>
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n暱稱:
      <view class='bk'>
        <!-- <textarea class="textarea" placeholder='暱稱' auto-height value='{{geren.nickname}}' maxlength='15'></textarea> -->
        <input name='nickname' class="textarea" placeholder="{{geren.nickname}}" value='{{geren.nickname}}' bindinput="nickname" maxlength='15' auto-height/>
      </view>
    </view>

    <view class='item'>
      真實姓名:
      <view class='bk'>
        <!-- <textarea class="textarea" placeholder='真實姓名' auto-height value='{{geren.sysUserDetail.realName}}' maxlength='10'></textarea> -->
        <input name='realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/>

      </view>
    </view>

    <view class='item'>
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n性別:
      <radio-group class="radio-group" bindchange="radioChange" name='gender'>

        <!-- <label class="radio" wx:for="{{items}}"> -->
        <label class='radio'>
          <!-- checked="{{item.checked}}" -->
          <radio value="{{items[0].name}}" checked='{{boy}}' /> {{items[0].value}}
          <radio value="{{items[1].name}}" checked='{{gril}}' /> {{items[1].value}}
        </label>

      </radio-group>
    </view>

    <view class='item'>
      \r\n\r\n\r\n\r\n\r\n\r\n\r\n生日:
      <view class='bk'>
        <view class='time'>
          <picker mode="date" value="{{date}}" start="1800-01-01" end="2222-01-01" bindchange="changeDate" name="birthday">
            <view>
              {{date}}
            </view>
          </picker>
        </view>
      </view>
    </view>

    <view class='item'>
      \r\n\r\n\r\n\r\n居住地:
      <view class='bk'>
        <!-- <textarea class="textarea" placeholder='居住地' auto-height value='{{geren.sysUserDetail.address}}' maxlength='10'></textarea> -->
        <view>
          <picker bindchange="changeRegin" mode="region" value="{{region}}">

            <!-- <view class="tui-picker-detail">{{region[0]}} - {{region[1]}} - {{region[2]}}</view> -->
            <view>{{region[0]}} - {{region[1]}} - {{region[2]}}</view>
          </picker>
        </view>
      </view>
      <view>
        <input name="address" style="display: none;" value="{{region}}" />
      </view>
    </view>

    <view class='item'>
      詳細地址:
      <view class='bk'>
        <!-- <textarea class="textarea" placeholder='詳細地址' auto-height value='{{geren.sysUserDetail.detailAddress}}' maxlength='100'></textarea> -->
        <input name="detailAddress" class="textarea" placeholder="{{detailgeren.detailAddress}}" value='{{detailgeren.detailAddress}}' bindinput="detailAddress" maxlength='100' auto-height/>

      </view>
    </view>

    <!-- <button class='btn' bindtap='baocun'>儲存</button> -->
    <view class='anniu'>
      <button class='btn' formType="submit">儲存</button>
      <!-- <button class='btn' formType="reset">重置</button> -->
    </view>

  </form>
</view>