微信小程序开发POST请求
代码语言:javascript复制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 ) {
}
})
代码语言:javascript复制微信小程序示例
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {
x: '' ,
y: ''
},
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log(res.data)
}
})
代码语言:javascript复制method: 'POST',
header:{
'content-type':'application/x-www-form-urlencoded'
},
代码语言:javascript复制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;
}
}
})
},
代码语言:javascript复制data: Util.json2Form( { cityname: "北京", key: "1430ec127e097e1113259c5e1be1ba70" }),
代码语言:javascript复制header: {"Content-Type":"application/x-www-form-urlencoded"},
代码语言:javascript复制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 //小程序关闭当前页面返回上一页面
})
},
})
代码语言:javascript复制<!--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>
代码语言:javascript复制<view class='bg'>
<view class='item'>
当前头像:
<open-data type="userAvatarUrl" class='img'></open-data>
</view>
<form bindsubmit="formSubmit" bindreset="formReset">
<view class='item'>
rnrnrnrnrnrnrn昵称:
<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'>
rnrnrnrnrnrnrn性别:
<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'>
rnrnrnrnrnrnrn生日:
<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'>
rnrnrnrn居住地:
<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>