javascript - How can I update a model attribute in JSP from the AJAX response? -
i have jsp page this
<li id="notifications"> <c:choose> <c:when test="${empty alerts}"> <p class="text-default">there no service reminders @ time</p> </c:when> <c:otherwise> <c:foreach items="${alerts}" var="alert"> <p class="text-default">${alert.serviceitemdescription}</p> </c:foreach> <button onclick="clearnotifications()" id="clearbutton" >clear </button> </c:otherwise> </c:choose> </li>
- the attribute {alerts} list.
- i want update existing list based on ajax response i'm getting below code.
- ajax "result" new list iterate. how can update existing model attribute "alerts" new value 'result' below code update 'list' tag element ?
< script type = "text/javascript" > function clearnotifications() { $.ajax({ type: "post", url: "/clearnotifications/" + $ { bike.id }, headers: { "accept": "text/html,application/json" }, success: function(result) { $("#notifications").html(result); } } }); } </script>
can try this,
in jsp, change li
follows,
<li id="notifications"> </li>
you can play js, specially ajax,
this page loads initially,
<script type="text/javascript"> $(document).ready(function() { alerts = ${alerts}; populatenotification(); }); function populatenotification(alerts) { for(var i=0; i<alerts.length; i++){ $("#notifications").html("<p class='text-default'>${alerts[i].serviceitemdescription}</p>"); } $("#notifications").append("<button onclick='clearnotifications()' id='clearbutton' >clear </button>"); }
this ajax calls,
function clearnotifications() { $.ajax({ type: "post", url: "/clearnotifications/" + $ { bike.id }, headers: { "accept": "text/html,application/json" }, success: function(result) { //$("#notifications").html(result); alerts = result; populatenotification(alerts); } } }); </script>
Comments
Post a Comment