实习效果:点击红色的叉进行删除时,整个页面地址不变,实现局部刷新
jsp页面中:
<pre name="code" class="java"><c:forEach items="${files}" var="item" varStatus="i"> <input type="hidden" id="fileId" value="${item.id}" /> <a style="display:inline-block;width: 250px;" href="download.htm?fileId=${item.id}&&assetId=${item.assetId}">${item.fileName}</a> <a style="color: red;background-color:ghostwhite;text-align: center;display:inline-block;width: 25px;" id="delete${i.count}">X</a><br/><br/> <script> $(document).ready(function() { $("#delete${i.count}").click(function () { $.ajax({ type:"POST",url:"filedelete.htm",data: {fileId:$("#fileId").val()},success:function () { window.location.reload(); } }) }) }) </script> </c:forEach>控制器中:
@RequestMapping("filedelete") public String fileDelete(Long fileId) { bizAssetReviewService.deleteFile(fileId); return "biz/asset/assetedit";//回到原来所在的jsp页面 }