नियंत्रक से मोडल पृष्ठ पर अपना डेटा पास करने का प्रयास कर रहा है।नियंत्रक से मॉड्यूल पृष्ठ
इस लिंक के बाद: 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>
तीसरा: मैं इस फाइल के अंत मैं बूटस्ट्रैप से एक सरल जावास्क्रिप्ट के साथ साथ एक ajax समारोह जोड़ें:
<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>
मैं सही ढंग से डेटाबेस से डेटा मिलता है, लेकिन मैं करने में सक्षम नहीं कर रहा हूँ मेरे मोडल एचटीएमएल पेज में डेटा दिखाएं।
अद्यतन 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 नहीं !!!
मैं मानों की सूची प्रदर्शित करना चाहते हैं, लेकिन एक साधारण पाठ दिखाने में असमर्थ ...
कोई सुझाव?
धन्यवाद
मोडल में मानों दिखाने में सक्षम नहीं है। फ़ायरबग शो मूल्य सही ढंग से।अपडेट किया गया प्रश्न – davisoski
क्या आप AJAX कॉल के बाद मोडल खोल रहे हैं, जहां मैंने टिप्पणी '// अंत में पॉपअप' खोल दी है? अगर आप AJAX कॉल से पहले मोडल खोलते हैं तो आप एक अपडेटेड डॉम नहीं दिखाएंगे –