Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Ajax 如何从JSON读取地图数据_Ajax_Json_Jquery_Spring 3 - Fatal编程技术网

Ajax 如何从JSON读取地图数据

Ajax 如何从JSON读取地图数据,ajax,json,jquery,spring-3,Ajax,Json,Jquery,Spring 3,我正在使用Spring3和JQuery 我想从我的Spring控制器返回Map{compose of elementID,its value} 并使用数据更新视图 控制器代码 @RequestMapping(value="/hpcCalResult") public ResponseEntity<Map<String, String>> calculateHeathPlanCost(HttpServletRequest request) { Map<

我正在使用Spring3和JQuery

我想从我的Spring控制器返回Map{compose of elementID,its value}

并使用数据更新视图

控制器代码

    @RequestMapping(value="/hpcCalResult")
public ResponseEntity<Map<String, String>>  calculateHeathPlanCost(HttpServletRequest request) {
    Map<String,String> requestMap = getMapFromRequest(request);
    boolean isError = false;
    Map<String,String> responseMap =  new HashMap<String, String>();
    try{
        responseMap = this.healthPlanService.getResponseMapAfterHPCostCalc(requestMap);
    }catch(HCException e){
        isError = true;
        responseMap.put("error", Springi18nUtils.getMessage(e.getMessageCode().getName(), null));
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    if(isError){
        return new ResponseEntity<Map<String, String>>(responseMap, headers, HttpStatus.INTERNAL_SERVER_ERROR);
    }else
        return new ResponseEntity<Map<String, String>>(responseMap, headers, HttpStatus.OK);
}
@RequestMapping(value=“/hpcCalResult”)
公共响应计算HEATHPLANCOST(HttpServletRequest请求){
Map requestMap=getMapFromRequest(请求);
布尔isError=false;
Map responseMap=newhashmap();
试一试{
responseMap=this.healthPlanService.getResponseMapAfterHPCostCalc(requestMap);
}捕获(HCE例外){
isError=真;
responseMap.put(“错误”,Springi18nUtils.getMessage(e.getMessageCode().getName(),null));
}
HttpHeaders=新的HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
如果(isError){
返回新的ResponseEntity(responseMap、Header、HttpStatus.INTERNAL_SERVER_错误);
}否则
返回新的ResponseEntity(responseMap、headers、HttpStatus.OK);
}
现在我想在JSP文件ajax请求中使用这个响应映射来更新ui

我的JQUERY代码是代码是:

 $("#Continue").click(function () {
            var form = $("#calculator");
            var data = form.serialize();
            $.post(form.attr("action"), data ,
                    function( data ) {
                             <<< dont know how to read the data as so that i can get key values which i will use to update the form fields . >>>

                        });
                    }   
            );
        });
$(“#继续”)。单击(函数(){
变量形式=$(“#计算器”);
var data=form.serialize();
$.post(form.attr(“操作”),数据,
功能(数据){
>
});
}   
);
});
请帮我解决同样的问题。
谢谢。

试图理解代码中的细节有点难。。。因此,我不确定我的回答是否对你有帮助。 但是,您是否尝试在javascript中使用eval()函数?用这种方式解码json是非常容易的。 大概是这样的:

var themap = new Object();
themap = eval( jsonedInstances );