Every time I try to run my code, I encounter an issue where I cannot access the URL specified in the getJSON function.
Below is my controller code:
@RequestMapping(value = "branch")
@Controller
public class BranchController {
@Autowired(required = true)
VillageService villageService;
@RequestMapping(value = "/addHome", method = RequestMethod.GET)
public @ResponseBody
List getForm1(@RequestParam("districtId") int districtId, Model model,
HttpServletRequest request, HttpServletResponse response) {
try {
villageList= villageService.getDistrictVillageList(districtId);
} catch (Exception er) {
log.error("error in addLoanType=" + er);
}
return villageList;
}
Here is my JavaScript code snippet:
<script>
$(document).ready(function() {
$("select#district").change(function() {
$.getJSON("/addHome", {districtId: $(this).val()}, function(j) {
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].id + '">' +
j[i].name + '</option>';
}
$("select#village").html(options);
});
});
});
</script>
I am facing a problem with my code. Can someone please assist me in resolving this issue?