0

我有 2 个下拉菜单的问题(第二个框选项取决于当前选择的第一个框选项)。我现在拥有的是: 控制器

@Controller
@RequestMapping(ADMINISTRATION)
{...}
    @RequestMapping(value = USERS + STUDENT + "/reloadGroups/{schoolId}", method = GET)
    public @ResponseBody
    List<StudyGroup> reloadGroups(@PathVariable(value = "schoolId") final int schoolId) {
        return studyGroupService.getStudyGroupBySchool(schoolService.getSchool(schoolId));
    }

html

    <script type="text/javascript">
                $(document).ready(
                    function() {
                        var selectSchool = $("#school");
                        var selectGroup = $("#studyGroup");

                        selectSchool.change(function() {
                            var schoolId = $("#school option:selected").val();

                            $.get("/administration/users/student/reloadGroups/"
                                    + schoolId, function(data) {
                                selectGroup.empty();
                                console.log(data);
                                var group = JSON.parse(data);
                                for ( var option in data) {
                                    selectGroup.append($("<option/>", {
                                        text : group[option].name,
                                        key : group[option].id
                                    }));
                                }
                            })

                        })
                    });
</script>
    //and of course 2 select boxes with ids 'school' and 'studyGroup'

我收到如下错误:

"NetworkError: 404 Not Found - http://localhost:8080/administration/users/student/reloadGroups/2"

但我不知道为什么,请求映射应该没问题。例如,当我在浏览器中输入http://localhost:8080/drdiet-web/administration/users/student/reloadGroups/1错误更改为 500 时:

"NetworkError: 500 Internal Server Error - http://localhost:8080/drdiet-web/administration/users/student/reloadGroups/1"

有什么问题?我是阿贾克斯的新手。

编辑

这之前“有效”,但不完全是,因为我只能更改第一个下拉值,因此它影响了第二个可用选项:

    $(document).ready(function() {
        var selectSchool = $("#school");
        var selectGroup = $("#studyGroup");


        selectSchool.change(function(){
                var schoolId = $("#school option:selected").val();

            $.ajax({
            url: config.baseUrl + '/administration/users/student/reloadGroups/' + schoolId,
            type: 'GET',
            data: schoolId,
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            dataType: 'text',
            error : function() {
                alert("error");
                console.log("error");
            },
            success: function(data){
                selectGroup.empty();
                var aaa = JSON.parse(data);
                console.log(data);
                alert("ok");
                for(var opt in aaa){
                    selectGroup.append($("<option/>", {
                        text: aaa[opt].name,
                        key: aaa[opt].id
                    }));
                console.log(aaa[opt]);
                }
            }
            })
        });
    });
4

1 回答 1

0

好的,错误 404 非常明显(config.baseUrl)。内部服务器错误(代码 500)是由控制器中不同类型的列表引起的。只是没看出来,谢谢大家的回复。

于 2013-03-07T10:07:27.700 回答