简体   繁体   中英

406 Not Acceptable error in Restcall

I am using ajax and spring.i am creating dynamic dropdown in my code.upto controller i am getting my dropdown.now i am creating a one ajax call to display dynaic values on my dropdown.when a make a ajax call i am getting 406 Not Acceptable 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

You need to have a space in between:

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

$('#adropdownDetails:selected').text() This might not be the value you are looking for. This is a whitespace or a new line character. you can check the snippet 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM