1

This is what I tried so far

<input id="allPlAccounts" type="hidden" th:value="${allPlAccounts}"/>

<script type="text/javascript">
    $("#printList").on('click', function () {

        var customers = ($("#allPlAccounts").val())

        $.ajax({
            type: "POST",
            url: "/coopmis/waterTariff/generateReport",
            data: JSON.stringify(customers),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {

            }
        });
    })
</script>

Below you can see my controller method.

@PostMapping(path = "/coopmis/waterTariff/generateReport",produces = "application/json;charset=UTF-8")
public void getCustomerByBranch(@RequestBody List<PlAccount> plAccountList) {

}

I want to send allPlAccounts arraylist to spring controller via ajax, How to do this?

Ruth Shaves
  • 124
  • 1
  • 1
  • 9
  • so what does `System.out.println(plAccountList);` gives? does that print required value ? – Swati May 22 '20 at 06:48
  • @Swati No, I add it whether to know end point hit – Ruth Shaves May 22 '20 at 06:52
  • @Swati I removed it – Ruth Shaves May 22 '20 at 06:53
  • 1
    debug from ajax call , check `customers` has required value or not ? i.e: `console.log(customers)` and then see if the url is right or not .Also ,check [this](https://stackoverflow.com/questions/20245544/how-to-pass-json-object-from-ajax-to-spring-mvc-controller) post and [here](https://stackoverflow.com/questions/18524524/passing-json-data-to-a-spring-mvc-controller) as well. – Swati May 22 '20 at 06:59

0 Answers0