点击提交页面不会改变,并且数据库中店铺信息也没有改变..
$(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
$('#submit').click(function () 提交函数放到了 function getShopInitInfo() 里面,当然无效咯,修改执行的是function getShopInfo(shopId) 。
把它拿出来就好了,另外这个js还有两个问题:
1、区域无法自动选取已有的。代码需要完善:
data.areaList.map(function (item, index) { if (item.areaId == shop.area.areaId) { tempAreaHtml += '<option data-id="' + item.areaId + '"selected>' + item.areaName + '</option>'; } else { tempAreaHtml += '<option data-id="' + item.areaId + '">' + item.areaName + '</option>'; } });
2、提交函数里面没有传shopId,加上:
shop.shopId = shopId;
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星