I want my javascript to access an object which is returned from the java controller. However it fails and gives the error "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method." in firebug. This is my javascript code.
var num = 1;
$.ajax({
type: "post",
url: "http://localhost:8080/Myapp/ajaxtest",
contentType: 'application/json',
data: num,
datatype: "json",
success: function(data){
alert("success");
//document.getElementById("tabtest").innerHTML = data;
},
error: function(){
alert("ERROR!");
}
and here is my controller method
@RequestMapping(value = "/ajaxtest", method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Plan> testingAjax(@RequestBody int num, SecurityContextHolderAwareRequestWrapper request) {
List<Plan> plans = planService.fetchPlans(request,num);
return plans;
}
When the program is run, it alerts ERROR!. Any help to figure this out is highly appreciated. thanks