e.detail.value.address.length==0){
wx.showToast({
title: '收货人所有信息不得为空!',
icon: 'loading',
duration: 1500
})
}else if(e.detail.value.mobile.length != 11){
wx.showToast({
title: '请输入11位手机号码!',
icon: 'loading',
duration: 1500
})
}else{
wx.request({
url: 'https://shop.yunapply.com/home/shipping/save',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
data:{id:e.detail.value.id,mobile:e.detail.value.mobile,name:e.detail.value.name,address:e.detail.value.address},
success: function(res) {
if(res.data.status == 0){
wx.showToast({
title: res.data.info,
icon: 'loading',
duration: 1500
})
}else{
wx.showToast({
title: res.data.info,
icon: 'success',
duration: 1000
})
setTimeout(function(){
wx.navigateTo({
url:'../address/index'
})
},1000)
}
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
})
}
}
在前端的FORM表单中,当点击formtype=“submit”这个按钮的时候,触发addSubmit事件,前面的if都是JS验证,防止用户不填写信息。
1.其他的request请求差不多,找几个不一样的
url: 'https://shop.yunapply.com/home/shipping/save',调用服务器端的save方法
header: {
"Content-Type": "application/x-www-form-urlencoded"
},由于POST和GET传送数据的方式不一样,POST的header必须是
"Content-Type": "application/x-www-form-urlencoded"GET的header可以是 'Accept': 'application/json'
data:{id:e.detail.value.id,mobile:e.detail.value.mobile,name:e.detail.value.name,address:e.detail.value.address},这里是需要POST到服务器端的数据
Save方法代码
public function save()
{
//$user_id
$user_id = 2;
if (IS_POST){
$shipping = D('Shipping');
if (!$shipping->create()){
$this->error($shipping->getError(),'',true);
}else{
if (is_numeric($_POST['id'])){
if ($shipping->editAddress($_POST['id'])){
$this->success('地址修改成功','',true);
}else{
$this->error('地址修改失败','',true);
}
}else{
if ($shipping->addAddress($user_id)){
$this->success('添加地址成功','',true);
}else{
$this->error('添加地址失败','',true);
}
}
}
}
}以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
微信小程序
向左滑动删除功能的实现
微信小程序button组件的使用介绍
以上就是微信小程序之增、删、改、查操作的代码实现的详细内容,更多请关注php中文网其它相关文章!
小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。
关键词:微信小程序之增、删、改、查设置的代码完成