公司实习对前端ajax,jquery的认识
2017-07-27 15:35
351 查看
1、前端发送ajax请求之后获取请求的列表
后端spring mvc
$(document).ready(function() { $.ajax({ url : '<%=request.getContextPath()%>/background/newskind/newskindList/0', dataType : 'json', cache : false, aysnc : false, success : function(response) { $.each(response,function(n,value) { $('#newskindSelect').append($("<option></option>").attr("value",value.id).text(value.name)); }); } }); $.ajax({ url : '<%=request.getContextPath()%>/background/specialschool/specialschoolList/0', dataType : 'json', cache : false, aysnc : false, success : function(response) { $.each(response,function(n,value) { $('#SpeciaSchoolSelect').append($("<option></option>").attr("value",value.id).text(value.schoolName)); }); } }); $('#newskindSelect').on("change",function(){ if(($("#newskindSelect").find("option:selected").text()=='院校专家')) { $("#SpeciaSchoolSpan").show(); $("#SpeciaSchoollabel").show(); }else{ $("#SpeciaSchoolSpan").hide(); $("#SpeciaSchoollabel").hide(); } }) ; }); <div class="row cl"> <label class="form-label col-2" ><span class="c-red">*</span>新闻类别:</label> <div class="formControls col-2"> <span class="select-box"> <select id="newskindSelect" name="newskindId" class="select"> <option value="1">全部分类</option> </select> </span> </div> <label id="SpeciaSchoollabel" class="form-label col-2" style="display:none"><span class="c-red">*</span>院校名称:</label> <div class="formControls col-2"> <span class="select-box" id="SpeciaSchoolSpan" style="display:none"> <select name="speciaSchool" id="SpeciaSchoolSelect" class="select"> <option value="1">全部分类</option> </select> </span> </div>2、前端发送ajax请求上传文件http://www.cnblogs.com/BigDreamer/p/5506340.html
$('.sub').click(function(e){ var data1 = new FormData($('#formupload')[0]); $.ajax({ type: 'post', url: "http://localhost:8080/pinghua-web/background/partner/create", data: data1, contentType: false, processData: false, dataType:'text', success: function(data){ if(data=="success"){ alert("上传成功");
}},error:function(err){ alert("err"+err);console.log(err);} });});
后端spring mvc
@RequestMapping(value = "/create", method = RequestMethod.POST)
public void create(HttpServletRequest request,HttpServletResponse response, @RequestParam(value="file" ,required=false) MultipartFile file, @Valid SchoolPartnerDTO schoolpartner, BindingResult result){ LOG.debug("*************** partner create, request str from web :" + schoolpartner + "***************"); String fileName=null; if(null!=file) { fileName=file.getOriginalFilename(); File introFile=new File(request.getServletContext().getRealPath("WEB-INF/intro"),fileName); try{ file.transferTo(introFile); }catch(IOException e){ e.printStackTrace(); } } String path="WEB-INF/intro/"+fileName; schoolpartner.setIntro(path); schoolpartner.setAddtime(new Date()); schoolpartner.setState(0); String msg="success"; Assert.notNull(schoolpartner); SchoolPartnerDTO newsTemp = partnerService.addSchoolPartner(schoolpartner); response.setHeader("Access-Control-Allow-Origin", "*"); PrintWriter out = null; try { out = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } out.print(msg); }
相关文章推荐
- 前端编程提高之旅(十七)----jquery中表单、表格和ajax
- 用ajax,将表单提交到后端,后端php向前端返回数组,前端通过jquery遍历
- web前端使用jQuery发送ajax请求并接受响应的代码公式
- 五滴水:使用Ajax+jQuery来实现前端收到的数据在console上显示+简单的主页设计与bootstrap插件实现图片轮播
- 前端技术Jquery与Ajax使用总结
- 简单的ajax让前端jquery与后台node.js交互
- .net jquery ajax应用(前端)
- j2ee学习笔记之前端(js、jQuery、html、html5、webService、ajax、css)—— 一直会补充
- 09.net网站开发(前端):6.类淘宝组合搜索效果jQuery+Ajax
- 对于jQuery中$.ajax方法的新认识
- jquery 中文教程和实例关注前端技术尽在-www.jqueryajax.com
- 简单认识JQuery的Ajax中的ajax()方法
- web前端之锋利的jQuery一:认识jQuery
- jquery+ajax实现前端新增和修改验证
- 前端开发:jQuery-ajax的封装
- web前端--知识点,笔记叠加(javascript,jquery,html5+css3.0,ajax)
- 后端数据传输到前端的两种方法(JQuery:AJAX 或 SpringMVC:ModelAndView)
- 如何使用struts框架做下拉框(前端jsp+jquery+ajax)
- jquery中ajax 从前端到后端 完整过程解析
- 前端 jquery-ajax 的简单案例分析和总结