I am trying to hit the url through jquery ajax but I am getting 406 in response.
I tried it through the postman extension through which I have found out that the response header is returning content-type : text/html but to get 200 response code it should be application/json. Please suggest some thing I have given up on this, I have tried everything checked every configuration but didn't find anything wrong. I can see the request is reaching the server getting processed but when the response is returned there is no error on the server side but it show error in the browser console.
Thanks in advance, waiting for the replies.
Method in controller
@RequestMapping(value="adminSectionBySub.html")
public @ResponseBody List<Section> getSectionsBySubjectId( @RequestParam String subjectId) {
//some code........
}
My Ajax call from JSP :
var obj = {
subjectId : $("#subjectId").val()
}
$.ajax({
url : "adminSectionBySub.html",
data : JSON.stringify(obj),
type : 'POST',
contentType : 'application/json',
success : function(response) {
alert("success " + response);
},
error : function(response) {
alert("error" + response);
}
});
This is the converter that I have defined:
<!--Configure bean to convert JSON to POJO and vice versa -->
<bean id="jsonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</bean>
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonMessageConverter" />
</list>
</property>
</bean>