Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Spring控制器未将列表返回到ajax成功函数中_Jquery_Ajax_Spring_Spring Mvc - Fatal编程技术网

Jquery Spring控制器未将列表返回到ajax成功函数中

Jquery Spring控制器未将列表返回到ajax成功函数中,jquery,ajax,spring,spring-mvc,Jquery,Ajax,Spring,Spring Mvc,我试图在春天自动完成。它的调用url,但不返回列表 我的控制器代码是这样的 @RequestMapping(value = "purchase/ajaxcitySearchGeneral", method = RequestMethod.GET) public@ResponseBody Map < String, List < MasterPart >> getZipcodes() { List < MasterPart > zipcodes =

我试图在春天自动完成。它的调用url,但不返回列表

我的控制器代码是这样的

@RequestMapping(value = "purchase/ajaxcitySearchGeneral", method = RequestMethod.GET)

public@ResponseBody Map < String, List < MasterPart >> getZipcodes()

{
    List < MasterPart > zipcodes = new ArrayList < MasterPart > ();
    List < MasterPart > zipcodes = itemService.getItem();
    System.out.println("Test Value" + zipcodes);
    Map < String, List < MasterPart >> zipMap = new HashMap < String, List < MasterPart >> ();

    zipMap.put("zipcodes", zipcodes);
    System.out.println("Test Value2" + zipMap);
    return zipMap;
}
@RequestMapping(value=“purchase/ajaxcitysearch-general”,method=RequestMethod.GET)
public@ResponseBodyMap>getZipcodes()
{
Listzipcodes=newarraylist();
Listzipcodes=itemService.getItem();
System.out.println(“测试值”+zipcodes);
Map>zipMap=newhashmap>();
zipMap.put(“zipcodes”,zipcodes);
系统输出打印项次(“测试值2”+zipMap);
返回zipMap;
}
Ajax代码如下所示

<script>
$(function () {
    $("#itemNameAuto").autocomplete({
        source: function (request, response) {

            $.ajax({
                url: 'ajaxcitySearchGeneral.htm',
                dataType: "json",
                data: {
                    maxRows: 10,
                    startsWith: request.term
                },

                success: function (data) {
                    alert(data);
                    response($.map(data.zipcodes, function (item) {
                        return {
                            label: item.name,
                            value: item.name
                        };
                    }));
                }
            });
        },

        minLength: 1,
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },

        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });
});
</script>

$(函数(){
$(“#itemNameAuto”).autocomplete({
来源:功能(请求、响应){
$.ajax({
url:'ajaxcitySearchGeneral.htm',
数据类型:“json”,
数据:{
马克斯罗:10,
startsWith:request.term
},
成功:功能(数据){
警报(数据);
响应($.map(data.zipcodes,函数(项)){
返回{
标签:item.name,
值:item.name
};
}));
}
});
},
最小长度:1,
打开:函数(){
$(this).removeClass(“ui角点全部”).addClass(“ui角点顶部”);
},
关闭:函数(){
$(this.removeClass(“ui角顶部”).addClass(“ui角全部”);
}
});
});

您返回的是Java HashMap,而不是JSON。您必须首先将JAVA映射转换为jSOn字符串

            return new JSONObject(map).toJSONString();

结帐

您在警报中得到了什么。。??