Update table using jQuery and controller in Spring?

1

What I'm looking for is that when I click on the button the comment table is updated asynchronously, that is, I'm loaded with a jquery function that updates a table in the JSP. I leave the code, because currently I miss the "alert" error:

Controller:

@RequestMapping(value="/updatecomments") 
public  @ResponseBody
String update(@RequestParam int lolMatchId){    
    Collection<CommentMatch> cm= commentMatchService.findAllByLolMatchId(lolMatchId);
    List<CommentMatch> cmatch = new ArrayList<CommentMatch>(cm);
    Collections.reverse(cmatch);
    Gson gson = new Gson();
    return gson.toJson(cmatch);
}

Jsp:

<form method="post">  
 <input type="button" value="Refresh" id = "b" onclick="searchAjax()" />
</form> 

<display:table name="commentsMatch" id="c" requestURI="lolMatch/match.do"     pagesize="5" class="displaytag" >

<display:column property="customer.name"  />
<display:column property="description"  />

</display:table>

<script type="text/javascript" src='js/jquery.min.js'></script>
<script type='text/javascript'>
  function searchAjax() {
        $.ajax({
            dataType : "json",
            url : "/${pageContext.request.contextPath}/updatecomments",
            headers : {
            'Accept' : 'application/json',
            'Content-Type' : 'application/json'
            },
            type: 'POST',
            success : function(response) {   

             $.each( response,function(key, comment) {
                 var htmlrow ="<tr><td>" + comment.description + "</td></tr>";         
                 $('#c').append(htmlrow);
             });
         },      
         error : function(){
             alert("error");
         }
     });
    }
</script>
    
asked by Fran-US 12.04.2016 в 00:00
source

1 answer

0

The method in your controller is waiting for a parameter called lolMatchId of type int.

In your ajax call I do not see the data attribute anywhere, I guess that is causing you the problem.

    
answered by 01.05.2016 в 08:16