I am using Spring 3 and JQuery.
I am want to return Map {consist of elementID , its value} from my Spring Controller
And use the data to update the View.
Controller Code
@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);
}
Now i want to use this response Map in JSP file ajax request to Update ui .
My JQUERY code is code is :
$("#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 . >>>
});
}
);
});
Kindly help me out over same. Thanks.
It's a bit heavy to try and understand the details in your code... hence, I'm not sure that my answer will help you. However, did you try to use eval() function in javascript? it is very easy to decode json's this way. something like this:
var themap = new Object();
themap = eval( jsonedInstances );