컨트롤러에서 모달 페이지로 데이터를 전달하려고합니다. 이 링크를컨트롤러에서 모달 페이지로 값 전달
: https://qtzar.com/2017/03/24/ajax-and-thymeleaf-for-modal-dialogs/
첫째 : 컨트롤러에서 간단한 방법은 데이터베이스
@PostMapping("/showarea")
public String areaModel(Model model) {
LOG.info("/showarea");
List<Zona> zonas = zonaService.findAll();
model.addAttribute("area", zonas.get(0).getNom_ZONA());
LOG.info("area: " + zonas.get(0).getNom_ZONA());
return "modal::modalContents";
}
쿼리하는 내 모델에서 지역을 넣어.
둘째 : 텍스트를 추가 할 수 https://v4-alpha.getbootstrap.com/components/modal/#modal-components
: 나는에서 예를 사용했다.
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#exampleModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true" th:fragment="modalContents">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p th:if="${area != null}" th:text="${area}" />
<p th:unless="${area == null}" >area == null</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save
changes</button>
</div>
</div>
</div>
</div>
셋째 : 나는 내가 부트 스트랩에서 간단한 자바 스크립트 플러스 아약스 기능을 추가하려면이 파일의 끝 : 내가 제대로 데이터베이스에서 데이터를 가져
<script>
$('#exampleModal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body input').val(recipient)
$.ajax({
type : 'POST',
url : "/showarea",
success : function(data) {
}
});
})
</script>
을,하지만 난 할 수 없을거야 모달 HTML 페이지에 데이터를 표시하십시오.
UPDATE 1 :
하지 내 모달의 데이터를 보여줄 수. 예를 들어 , 나는 자바 스크립트
<div class="modal-body" id="areaValue">
<p id="area" th:if="${area != null}" th:text="${area}" />
</div>
추가 : 불을 지르고와
$.ajax({
type : 'POST',
url : "/showarea",
success : function(data) {
$('#areaValue').html(data);
}
});
디버깅 내가 모달의 값을 얻을 수 있지만, showded하지!
I 값의 목록을 보여 좋아하지만 간단한 텍스트를 표시 할 수 없습니다 것입니다 ...
어떤 제안이? 난 당신이
- 테이크 값에 순서에 AJAX 호출을하고 있다는 것을 이해하는 코드를 읽어
감사
를 바랍니다. 파이어 버그가 올바르게 표시됩니다.업데이트 된 질문 – davisoski
ajax 호출 다음에 모달을 여는 중입니다. '/ 마지막으로 열려있는 팝업'으로 주석을 달았습니다. ajax 호출 전에 모달을 여는 경우 업데이트되지 않은 DOM이 표시됩니다. –