P
P
postya2019-11-07 18:06:23
Spring
postya, 2019-11-07 18:06:23

How to load template from different url without page reload in Thymeleaf?

I need a pop-up modal window with a different template to appear when the button is clicked, but the current html page remains
. In the template, I have a button that calls a method in the controller:

<a data-modal-target="#modal" th:href="@{'/face/' + ${contact.id}}" class="view">
  <button  class="btn btn-primary"><i class="fa fa-eye"> View</i></button>
</a>

@GetMapping("/face/{id}")
  public ModelAndView viewFullFace(@PathVariable(name = "id")int id, Model model) {
    List<Contact> listContacts = contactService.getAll();
    model.addAttribute("listContacts", listContacts);
    ModelAndView mav = new ModelAndView("view_face");
    Contact contact = contactService.get(id).orElse(null);
    mav.addObject("contact", contact);
    return mav;
  }

when the button is clicked, the url changes to another one and another template is called
. How can I prevent the page from reloading when changing the url?
Can you tell me any tutorials on creating modal windows in thymeleaf

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2019-11-07
@postya

Hello!
Learn ajax technology. And also SPA (single page application)
you can just send an ajax request to the server. Return template with already substituted values ​​and show modal window

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question