微信小程序开发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  //小程序关闭当前页面返回上一页面
        })
      },
    })
复制代码


'bg'>
  'item'>
    身份认证
    'bk'>
      
      'idCard' class="textarea" placeholder="{{detailanquan.idCard}}" value='{{detailanquan.idCard}}' bindinput="idCard" maxlength='15' auto-height/>

    
    
  
  "line">

  'item'>
    登录密码
    'bk'>
      
      'password' class="textarea" placeholder="{{anquan.password}}" value='{{anquan.password}}' bindinput="password" maxlength='100' auto-height/>

    
    
  
  "line">

  'item'>
    绑定手机
    'bk'>
      
      'phone' class="textarea" placeholder="{{anquan.phone}}" value='{{anquan.phone}}' bindinput="phone" maxlength='15' auto-height/>

    
    
  
  "line">

  'item'>
    绑定邮箱
    'bk'>
      
      'email' class="textarea" placeholder="{{anquan.email}}" value='{{anquan.email}}' bindinput="email" maxlength='30' auto-height/>

    
    
  
  "line">

  'item'>
    微信绑定
    'bk'>
      
      'wxUnionid' class="textarea" placeholder="{{anquan.wxUnionid}}" value='{{anquan.wxUnionid}}' bindinput="wxUnionid" maxlength='100' auto-height/>

    
    
  
  "line">

复制代码

'bg'>
  'item'>
    当前头像:
    type="userAvatarUrl" class='img'>
  

  
"formSubmit" bindreset="formReset"> 'item'> \r\n\r\n\r\n\r\n\r\n\r\n\r\n昵称: 'bk'> 'nickname' class="textarea" placeholder="{{geren.nickname}}" value='{{geren.nickname}}' bindinput="nickname" maxlength='15' auto-height/> 'item'> 真实姓名: 'bk'> 'realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/> 'item'> \r\n\r\n\r\n\r\n\r\n\r\n\r\n性别: "radio-group" bindchange="radioChange" name='gender'> 'item'> \r\n\r\n\r\n\r\n\r\n\r\n\r\n生日: 'bk'> 'time'> "date" value="{{date}}" start="1800-01-01" end="2222-01-01" bindchange="changeDate" name="birthday"> {{date}} 'item'> \r\n\r\n\r\n\r\n居住地: 'bk'> "changeRegin" mode="region" value="{{region}}"> {{region[0]}} - {{region[1]}} - {{region[2]}} "address" style="display: none;" value="{{region}}" /> 'item'> 详细地址: 'bk'> "detailAddress" class="textarea" placeholder="{{detailgeren.detailAddress}}" value='{{detailgeren.detailAddress}}' bindinput="detailAddress" maxlength='100' auto-height/> 'anniu'>
复制代码

你可能感兴趣的:(微信小程序开发POST请求)