修改完店铺信息后,点击提交没有作用,数据库中数据也没有发生改变
$(function () {
var shopId=getQueryString('shopId');
var isEdit=shopId?true:false;
var initUrl = '/o2o_war_exploded/shopadmin/getshopinitinfo';
var registerShopUrl = '/o2o_war_exploded/shopadmin/registershop';
var shopInfoUrl='/o2o_war_exploded/shopadmin/getshopbyid?shopId='+shopId;
var editShopUrl='/o2o_war_exploded/shopadmin/modifyshop';
if( !isEdit){
getShopInitInfo();
}else{
getShopInfo(shopId);
}
function getShopInfo(shopId) {
$.getJSON(shopInfoUrl,function (data) {
if(data.success){
var shop=data.shop;
$('#shop-name').val(shop.shopName);
$('#shop-addr').val(shop.shopAddr);
$('#shop-phone').val(shop.phone);
$('#shop-desc').val(shop.shopDesc);
var shopCategory='<option data-id="'
+ shop.shopCategory.shopCategoryId +'"selected>'
+ shop.shopCategory.shopCategoryName + '</option>';
var tempAreaHtml = '';
data.areaList.map(function (item,index) {
tempAreaHtml += '<option data- id="' + item.areaId + '">'
+ item.areaName + '</option>';
});
$('#shop-category').html(shopCategory);
$('#shop-category').attr('disabled','disabled');
$('#area').html(tempAreaHtml);
$("#area option[data-id=]'"+ shop.area.areaId+ "']").attr("selected","selected");
}
});
}
function getShopInitInfo() {
$.getJSON(initUrl,function (data) {
if(data.success){
var tempHtml = '';
var tempAreaHtml = '';
data.shopCategoryList.map(function(item,index){
tempHtml += '<option data-id="'+item.shopCategoryId +'">'
+item.shopCategoryName + '</option>>';
})
data.areaList.map(function (item, index) {
tempAreaHtml += '<option data-id="' + item.areaId +'">'
+ item.areaName +'</option>';
})
$('#shop-category').html(tempHtml);
$('#area').html(tempAreaHtml);
}
});
// 提交按钮的事件响应,分别对店铺注册和编辑操作做不同响应
$('#submit').click(function () {
var shop ={};
if (isEdit){
shop.shopId =shopId;
}
//shop.shopName = $('#shop-name').val();
shop.shopName = $('#shop-name').val();
shop.shopAddr= $('#shop-addr').val();
shop.phone= $('#shop-phone').val();
shop.shopDesc= $('#shop-desc').val();
shop.shopCategory= {
shopCategoryId : $('#shop-category').find('option').not(function () {
return !this.selected;
}).data('id')
};
shop.area = {
areaId : $('#area').find('option').not(function () {
return !this.selected;
}).data('id')
};
var shopImg =$('#shop-img')[0].files[0];
var formData= new FormData();
formData.append('shopImg',shopImg);
formData.append('shopStr',JSON.stringify(shop));
var verifyCodeActual =$('#j_captcha').val();
if(!verifyCodeActual){
$.toast("请输入验证码!");
return;
}
formData.append('verifyCodeActual',verifyCodeActual);
$.ajax({
url : (isEdit? editShopUrl: registerShopUrl),
type : 'POST',
data : formData,
contentType : false,
processData : false,
cache : false,
success : function (data) {
if(data.success()){
$.toast('提交成功!!');
}else{
$.toast('提交失败!!' + data.errMsg);
}
$('#captcha_img').click();
}
});
});
}
})
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星