直接报500错误
没有加验证码之前,做了一个小测试无法添加
$(function () { var initUrl = '/shopadmin/getshopinitinfo'; var registerShopUrl = '/shopadmin/registerShop'; getshopinitinfo(); function getshopinitinfo() { $.getJSON(initUrl, function (data) { if (data.success) { var categoryHtml = ''; var areaHtml = ''; data.catagoryList.map(function (item, index) { categoryHtml += '<option data-id="' + item.shopCategoryId + '">' + item.shopCategoryName + '</option>'; }) data.areaList.map(function (item, index) { areaHtml += '<option data-id="' + item.areaId + '">' + item.areaName + '</option>'; }) $('#shop-category').html(categoryHtml); $('#shop-area').html(areaHtml); $('#submit').click(function () { var shop = {}; 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: $('#shop-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); // 将shop json对象转成字符流保存至表单对象key为shopStr的的键值对里 formData.append('shopStr', JSON.stringify(shop)); console.log(shop) $.ajax({ url: registerShopUrl, type: 'POST', data: formData, contentType: false, processData: false, cache: false, success: function (data) { if (data.success) { $.toast('提交成功!'); } else { $.toast('提交失败!' + data.errMsg); } } }); }); } }) } })
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>店铺信息</title> <meta name="description" content="MSUI: Build mobile apps with simple HTML, CSS, and JS components."> <meta name="author" content="阿里巴巴国际UED前端"> <meta name="viewport" content="initial-scale=1, maximum-scale=1"> <link rel="shortcut icon" href="/favicon.ico"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <!-- Google Web Fonts --> <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.css"> <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.css"> <script> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?ba76f8230db5f616edc89ce066670710"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </head> <body> <div class="page-group"> <div id="page-layout" class="page"> <header class="bar bar-nav"> <a class="button button-link button-nav pull-left back" href="/demos/form"> <span class="icon icon-left"></span> 返回 </a> <h1 class="title">店铺信息</h1> </header> <div class="content"> <div class="list-block"> <ul> <!-- Text inputs --> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-name"></i></div> <div class="item-inner"> <div class="item-title label">店铺名称</div> <div class="item-input"> <input type="text" placeholder="店铺名称" id="shop-name"> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-gender"></i></div> <div class="item-inner"> <div class="item-title label">商铺分类</div> <div class="item-input"> <select id="shop-category"> </select> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-gender"></i></div> <div class="item-inner"> <div class="item-title label">所属区域</div> <div class="item-input"> <select id="shop-area"> </select> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-email"></i></div> <div class="item-inner"> <div class="item-title label">详细地址</div> <div class="item-input"> <input type="text" placeholder="详细地址" id="shop-addr"> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-email"></i></div> <div class="item-inner"> <div class="item-title label">联系电话</div> <div class="item-input"> <input type="text" placeholder="联系电话" id="shop-phone"> </div> </div> </div> </li> <li> <div class="item-content"> <div class="item-media"><i class="icon icon-form-email"></i></div> <div class="item-inner"> <div class="item-title label">缩略图</div> <div class="item-input"> <input type="file" placeholder="联系电话" id="shop-img"> </div> </div> </div> </li> <li class="align-top"> <div class="item-content"> <div class="item-media"><i class="icon icon-form-comment"></i></div> <div class="item-inner"> <div class="item-title label">店铺简介</div> <div class="item-input"> <textarea id="shop-desc"></textarea> </div> </div> </div> </li> </ul> </div> <div class="content-block"> <div class="row"> <div class="col-50"><a href="#" class="button button-big button-fill button-danger">返回</a></div> <div class="col-50"><a href="#" class="button button-big button-fill button-success" id="submit">提交</a></div> </div> </div> </div> </div> </div> <script type='text/javascript' src='/resources/js/shop/jquery-3.3.1.js'/> <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.js' charset='utf-8'></script> <script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.js' charset='utf-8'></script> <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.js' charset='utf-8'></script> <script type='text/javascript' src='../resources/js/shop/shopoperation.js' charset='utf-8'></script> </body> </html>
进到后台无法获取到值
19
收起
正在回答
5回答
同学有没有在这个spring-web.xml 中配置文件上传解析器呢?
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
慕无忌6012795
2019-03-27 11:48:49
注释的是我写的,上面是cp老师的,为什么老师的可以,而我的不行
慕无忌6012795
2019-03-27 10:38:50
加了验证码后 , 验证码也是获取不到,也是直接报错了
慕无忌6012795
2019-03-26 19:38:54
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星