I have the following Spring Controller
@Controller
@RequestMapping("/accreq")
with the following mapping and file similar to org.springframework.samples.mvc.ajax.account.AvailabilityStatus with an extra boolean field someBooleanValue
@RequestMapping(value = "/defRoles", method=RequestMethod.GET)
public @ResponseBody AvailabilityStatus loadDefaultRoles(
@RequestParam(value="idGroup", required=false) String groupID {
I'm trying to call this method with the following jquery ajax
$.getJSON("${pageContext. request. contextPath}/accreq/defRoles.htm", { idGroup: $('#infoGroup').val() }, function(availability) {
if (availability.someBooleanValue) {
//Do this
} else {
//Do else
}
});
Spring method is being executed but I get a 406 response back. What dataType I need to set to get a successful response? This use to work under Spring 3.1.4 and now it does not work on higher version of Spring like 3.2.4 or 4.0.0. In short, how to handle object return in Ajax response?
Response header - 406 Error
Request Headersview source
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Config
<context:component-scan base-package="com.X" />
<mvc:annotation-driven />
<cache:annotation-driven />
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
...mapping for controller.....database etc
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="cache" value="true" />
<property name="order" value="1" />
</bean>
getJSONmethod is sending the data as JSON to the server and not as a request parameter. So basically your content send to the server is JSON whereas spring expects it to be a request parameter.406error?Ajaxcall likedataType: "text",or some other type for the object (if there exists any)? Wondering how this worked for 3.1.4?