D
D
DrRafael2020-10-11 18:30:37
JavaScript
DrRafael, 2020-10-11 18:30:37

How to pass parameter from ajax to spring boot controller?

Good afternoon! Newbie in programming. Can you please tell me how to transfer data to the controller?

<script>
    var  filter = document.getElementById("filter");
    filter.onchange = function(){
    console.log(this.value);

    $.ajax({
        url: "/filter",
        type: 'GET',
        data: this.value,
        contentType: "application/json",
        success: function( data ) {
        $("body").html(data);
        console.log(data);
        },
        dataType: 'json',
        cache: false,
        contentType: false,
        processData: false

        });
    };

</script>


@RequestMapping(value = "/filter", method = RequestMethod.GET)
    public String filter(@ModelAttribute  String printEditionCategory, Map<String, Object> model){
        Iterable<PrintEdition> printEditions = printEditionRepo.findAll();
        model.put("printEdition",printEditions);
        System.out.println("!!!!!!!!!" + printEditionCategory);

        return "index";

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question