jquery Ajax not working with Spring 3.2.3 -
i trying learn spring mvc + jquery ajax getting error on ajax success, following code configuration
jquery ajax.
$.ajax({ type:"get", url:"" +attr.url +"", contenttype: "application/json", success:function(response){ console.log("response length",response.length); }, error:function(e){ } });
spring controller
@requestmapping(value ="/getlist.htm", method= requestmethod.get) public @responsebody list<someclass> _givelist(httpservletresponse response) throws daexception{ list<someclass>someclass = isomeclass.getdata(); return someclass; }
this method executing , can see size of someclass. jackobjectmapper configuration in applicationcontext.xml
<bean id="jacksonobjectmapper" class="org.codehaus.jackson.map.objectmapper"></bean> <bean id="jacksonmessagechanger" class="org.springframework.http.converter.json.mappingjacksonhttpmessageconverter"> <property name="supportedmediatypes" value="application/json"/> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter"> <property name="messageconverters"> <list> <ref bean = "jacksonmessagechanger"/> </list> </property> </bean>
jackson dependency in pom.xml
<dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.2.3</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> <version>2.2.3</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-annotations</artifactid> <version>2.2.3</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-core-asl</artifactid> <version>1.9.13</version> </dependency> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.9.13</version> </dependency>
the controller method executing there no response in ajax request.so not seeing console log of ajax success function. getting error
the resource identified request capable of generating responses characteristics not acceptable according request "accept" headers. tried resolve adding headers = "application/json".but no luck. appreciable.
the issue you're facing typical when spring mvc framework fails convert representation (in case json
) from/to java object. can happen on account of error in configuring converter, or error in process.
your case former, spring 3.x
should remove current jackson dependencies , use e.g.
<dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-mapper-asl</artifactid> <version>1.9.13</version> </dependency>
com.fasterxml.jackson
package used jackson 2.x
being used spring 4.x
versions.
with current code, effect same not having jackson
dependencies @ all, in charge conversion json/java conversion, , why you're getting error
Comments
Post a Comment