Below is the SOAPUI (GET) response when I hit: http://localhost:8082/getCountries
HTTP/1.1 200
Content-Type=application/json
Transfer-Encoding=chunked
Date=Mon, 18 May 2020 03:38:46 GMT
Keep-Alive=timeout=60
Connection=keep-alive
[{"countryId":91,"countryName":"India"},{"countryId":94,"countryName":"SriLanka"}]
And below is the jsp page with the Jquery-Ajax code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Cascading Dropdown</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    alert("Hello");
    $.ajax({
        url: "http://localhost:8082/getCountries"
    }).then(function(result) {
        alert("Success");
        var result = JSON.parse(result);
        var s = '';
        for(var i = 0; i < result.length; i++) {
            s += '<option value="' + result[i].countryId + '">' + result[i].countryName + '</option>';
        }
        $('#comboboxCountry').html(s);
    });
});
</script>
</head>
<body>
    <form>
        <table>
            <tr>
                <td>Country</td>
                <td>
<select id="comboboxCountry" style="width: 200px"></select>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
I am using two projects here. one is producing the JSON array, and another is consuming. I am posting both the controllers below:
- Producing Controller: - @Controller public class MainController { @Autowired private MainService mainService; @ResponseBody @GetMapping(path = "/getCountries",produces = "application/json") public List<Country> getCountires(){ return mainService.findAll(); } @ResponseBody @GetMapping(path = "/getStates/{countryId}",produces = "application/json") public List<State> getStates(@PathVariable("countryId") Integer countryId){ return mainService.findbyId(countryId); } }
- Consuming controller: - @Controller public class MainController { @RequestMapping("/") public String home(Model model) { System.out.println("loading welcome page"); return "welcome"; } }
 
     
    