實習效果:點擊紅色的叉進行刪除時,整個頁面地址不變,實現局部重新整理
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頁面}