java - 如何在没有 location.reload() 的 POST 请求后刷新页面内容
问题描述
目标
在 POST 请求之后,我想更新一个列表。例如,如果添加了一个用户,则必须刷新用户列表。
所以我做了发布请求,然后我做了一个获取请求来更新内容。
有没有办法在不重新加载页面的情况下做到这一点?
感谢您的回答!
阿贾克斯调用
function rafraichirContenu(url, type) {
$.ajax({
url: url,
type: type
}).done(function (response) {
$(document).html(response)
});
}
postRequest().done(function(response) {
rafraichirContenu('/emprunts/encours', 'GET');
...
});
获取映射
@GetMapping(value = "/encours")
public ModelAndView findAllEnCours() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("emprunts", empruntResource.getEmpruntsByStatutEquals(StatutEmprunt.EN_COURS));
modelAndView.setViewName("webapp/pages/emprunts");
return modelAndView;
}
HTML
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionEmprunts">
<div class="card-body">
<table class="table">
<thead>
<tr>
<th scope="col">Usager</th>
<th scope="col">Exemplaire</th>
<th scope="col">Date de rendu</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody>
<th:block th:each="emprunt : ${emprunts}">
<tr>
<!--/*@thymesVar id="emprunt" type="bibliotheque.model.Emprunt"*/-->
<td th:text="${emprunt.getUsager().getMail()}"></td>
<td th:text="${emprunt.getExemplaire().getOeuvre().getTitre()}"></td>
<td th:text="${emprunt.getDaterendu()}"></td>
<td th:text="${emprunt.getStatut()}"></td>
</tr>
</th:block>
</tbody>
</table>
</div>
</div>
控制台错误
jquery.min.js:2 未捕获的类型错误:无法读取 null 的属性“createDocumentFragment”
解决方案
推荐阅读
- google-api - Google gapi.auth2.getAuthInstance().isSignedIn().get() 在多个 google 帐户时始终为 false
- c++ - 数组大小超过 CPP 中的最大对象大小
- python - 尝试对字典中具有某些相似性的不同值进行分组
- swift - 如何使用 GameKit 将默认值设为 0
- ssh - 如何将已知指纹传递给 SSH(为了避免手动提示)
- c# - 带有 inputData 的反向列表
- sql-server - SSMS won't connect to SQL Server 2019
- typeform - 如何在 typeform API 中获取签名和landed_at 数据?
- python - 以下代码的时间复杂度是多少?
- c++ - 无法提升程序权限