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>

  1. the attribute {alerts} list.
  2. i want update existing list based on ajax response i'm getting below code.
  3. 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

Popular posts from this blog

javascript - How to bind ViewModel Store to View? -

recursion - Can every recursive algorithm be improved with dynamic programming? -

c - Why does alarm() cause fgets() to stop waiting? -