POST请求后如何在没有location.reload()

时间:2019-03-10 11:01:33

标签: java jquery ajax spring spring-mvc

目标

在POST请求之后,我想更新一个列表。例如,如果添加了用户,则必须刷新用户列表。

因此,我执行发布请求,然后执行获取请求以更新内容。

有没有一种方法而无需重新加载页面?

谢谢您的回答!

Ajax呼叫

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未捕获的TypeError:无法读取null的属性'createDocumentFragment'

0 个答案:

没有答案
相关问题