ajax前端局部页面刷新
作者:互联网
1.jsp
<div class="center-left"> <div class="center-left-title"> <%--<span><a href="/kms/knowledgeView/knowledgeDatas.do?type=1" >本月知识浏览前十排行</a></span>--%> <%--<span><a href="/kms/knowledgeView/knowledgeDatas.do?type=2">本季度知识浏览</a></span>--%> <%--<span><a href="#">半年度知识浏览</a></span>--%> <%--<span><a href="/kms/knowledgeView/knowledgeDatas.do?type=4">本年度知识浏览</a></span>--%> <span><a id="knowledgeMonth" class="glideLine" onclick="curMonths('1')">本月知识浏览前十排行</a></span> <span><a id="knowledgeQuarter" onclick="curMonths('2')">本季度知识浏览</a></span> <span><a id="knowledgeHYear" href="#">半年度知识浏览</a></span> <span><a id="knowledgeYear" onclick="curMonths('4')">本年度知识浏览</a></span> </div> <div class="left-list-title"> <span>名称</span> <p>次数</p> </div> <div class="center-left-list" id="addHtml"> <%--<ul>--%> <%--<c:forEach items="${data.list}" var="list">--%> <%--<li>--%> <%--<span title="${list.objname}">--%> <%--<a target="_blank" href="/vdocument/base/docbaseview.jsp?id=${list.id}">--%> <%--${fn:length(list.objname)>55 ? fn:substring(list.objname, 0, 55) : list.objname }--%> <%--${fn:length(list.objname)>55 ? '...' : '' }--%> <%--</a>--%> <%--</span>--%> <%--<p>${list.num}</p>--%> <%--</li>--%> <%--</c:forEach>--%> <%--</ul>--%> </div> </div>
2.js:定义一个全局让加载页面时加载方法
var reg="1"; $(function () { curMonths(reg); }) function curMonths(reg) { console.log(reg) if (reg=="1") { $('#knowledgeMonth').addClass("glideLine"); $('#knowledgeQuarter').removeClass("glideLine") $('#knowledgeHYear').removeClass("glideLine") $('#knowledgeYear').removeClass("glideLine") }else if (reg=="2"){ $('#knowledgeMonth').removeClass("glideLine"); $('#knowledgeQuarter').addClass("glideLine") $('#knowledgeHYear').removeClass("glideLine") $('#knowledgeYear').removeClass("glideLine") }else if (reg=="3"){ $('#knowledgeMonth').removeClass("glideLine"); $('#knowledgeQuarter').removeClass("glideLine") $('#knowledgeHYear').addClass("glideLine") $('#knowledgeYear').removeClass("glideLine") } else { $('#knowledgeMonth').removeClass("glideLine"); $('#knowledgeQuarter').removeClass("glideLine") $('#knowledgeHYear').removeClass("glideLine") $('#knowledgeYear').addClass("glideLine") } var insertHtml = ""; $.ajax({ url: "/kms/knowledgeView/knowledgeDatas.do", type: "POST", data: {type: reg}, dataType: "json", success: function (data) { var result = data.data.list; insertHtml += " <ul>\n"; for (var p in result) { insertHtml += " <li>\n" + " <span title=\""+result[p].objname+"\">\n" + " <a target=\"_blank\" href=\"/vdocument/base/docbaseview.jsp?id=\""+result[p].objname+"\">"+result[p].objname+"</a>\n" + " </span>\n" + " <p>"+result[p].num+"</p>\n" + " </li>"; } insertHtml += "</ul>"; $('#addHtml').html(insertHtml) } });
3.controller:json返回
/** * 知识浏览月前十、季度、半年、年度 */ @RequestMapping("/kms/knowledgeView/knowledgeDatas") public void knowledgeDatas(HttpServletRequest request, HttpServletResponse response) throws IOException { JSONObject jsonObject=new JSONObject(); PrintWriter writer = response.getWriter(); KnowledgeSearchVo vo= WebUtils.requestToBean(request,KnowledgeSearchVo.class); Map<String,Object> data=knowledgeViewService.knowledgeData(vo); jsonObject.put("data",data); writer.write(jsonObject.toString()); System.out.println(">>>>>>>>>>>>>>"+data); writer.close(); }
标签:浏览,removeClass,glideLine,ajax,刷新,--%,data,reg,页面 来源: https://www.cnblogs.com/jk200/p/15497452.html