406 Invalid error in Restcall

I use ajax and spring. I am creating a dynamic popup menu in my code.upto controller. I get my dropdown.now. I create one ajax call to display dynamic values ​​on my drop down list. When make an ajax call I get 406 invalid error

This is my code.

<script>
    $(document).ready(function() {
        $("#adropdownDetails").change(function() {
            var value = $('#adropdownDetails:selected').text();
            $.ajax({
                type : 'POST',
                url : 'envi',
                data : {
                   selectedaname :$('#adropdownDetails:selected').text()
                },
                success : function() {
                    alert("success");
                }
            });
        });
     });
</script>

This is my ajax call. This is my controller

@RequestMapping(value = "/envi", method = RequestMethod.POST)
      public @ResponseBody List<Environments> getEnvironmentNames(@RequestParam String selectedaname ) throws SQLException {
        List<org.mvc.domain.Environments> environmentnamesList = loginDelegate.getEnvironments(selectedcustomername);
        System.out.println("envi size"+environmentnamesList.size());
        return environmentnamesList;
    }

thanks in advance

+4
source share
1 answer

You need to have a gap between:

$('#adropdownDetails :selected').text()

$('#adropdownDetails:selected').text()This may not be the value you are looking for. This is a character whitespaceor a new character in a string. You can check the picture below:

var selval = $('select:selected').text();
$('pre').html('<p>'+selval+'</p>');
p{border:solid 1px grey; padding:2px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select><option>select...</option></select>
<pre></pre>
Run codeHide result
0
source

Source: https://habr.com/ru/post/1616489/


All Articles