Here is my Jquery Ajax code:
And the controller:Code:$.ajax({ headers: ({ 'Accept': 'application/json', 'Content-Type': 'application/json' }), type: 'GET', url: '/abc/main/ajax/players/play.html', data: ({playerId : playerId}), dataType: 'json', async: true, success: function(data) { $('#plays').html(data); }, error: function(jqXHR, textStatus, errorThrown) { alert("Issue fetching the JSON: " + textStatus + " " + errorThrown + " !"); }
and the configuration:Code:@RequestMapping(value = "/main/ajax/players/orders", method = RequestMethod.GET) public @ResponseBody List<Play> getPlays(@RequestParam int playerId) { List<Play> ps = new ArrayList<Play>(); // .. return ps; }
and the error:Code:<context:component-scan base-package="com.xyz.abc.controller" /> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> <mvc:annotation-driven validator="validator" /> <mvc:interceptors> <bean name="generalParameterInterceptor" class="com.xyz.abc.interceptor.GeneralParameterInterceptor" /> </mvc:interceptors> <mvc:resources mapping="/static/**" location="/static/" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>
The controller code is executed. So, the error between the controller and the page. Here is the browser information:Code:HTTP Status 406 - type Status report message description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
With an assumption of the inconsistent content type, text/html vs. application/json, changing the "text/html" to "application/json" will resolve the problem. My question is how to make the content type?Code:Connection Keep-Alive Content-Length 1067 Content-Type text/html;charset=utf-8 Date Sat, 09 Mar 2013 00:10:17 GMT Keep-Alive timeout=5, max=100 Request Headersview source Accept application/json Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Connection keep-alive Content-Type application/json Cookie JSESSIONID=7835BA621612B6CCBA4D0BC7999B56D2; gzid="20130221:037af114f235869367f7ee0727472239"; epid="qYesdVkNRjmr3DmKO/ZtTXJzbGTSylYr"; ep=aa50cc6cf41f7ae7eccd2ef7aab79ece; ev=0; pid=11517928 Host www.zylomlocal.com Referer http://www.xyz.com/abc/ User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 X-Requested-With XMLHttpRequest


Reply With Quote