ajax 406,ajax - Problem with Spring 3 + JSON : HTTP status 406? - Stack Overflow

I'm trying to get a list of Cities by sending the State name through Ajax in my SpringMVC 3.0 project.

For the purpose, I've used the following call (using jQuery) in my JSP:

function getCities() {

jq(function() {

jq.post("getCities.html",

{ stateSelect: jq("#stateSelect").val()},

function(data){

jq("#cities").replaceWith('Testing');

});

});

}

And here's my Controller code:

@RequestMapping(value = "/getCities", method = RequestMethod.POST)

public @ResponseBody List getCities(@RequestParam(value="stateSelect", required=true) String stateName,

Model model) {

// Delegate to service to do the actual adding

List listStates = myService.listCityNames(stateName);

// @ResponseBody will automatically convert the returned value into JSON format

// You must have Jackson in your classpath

return listStates;

}

But I get HTTP 406 error stating the following when i run it:

406 Not Acceptable

The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.

I've used Jackson in my Maven dependencies & have defined in my context file.

I've googled extensively & I guess the problem is @ResponseBody is not automatically converting my List to appropriate JSON object.

My Firebug says:

Response Headers

Server Apache-Coyote/1.1

Content-Type text/html;charset=utf-8

Content-Length 1070

Date Sat, 12 Feb 2011 13:09:44 GMT

Request Headers

Host localhost:8080

User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

Accept */*

Accept-Language en-us,en;q=0.5

Accept-Encoding gzip,deflate

Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 115

Connection keep-alive

Content-Type application/x-www-form-urlencoded; charset=UTF-8

X-Requested-With XMLHttpRequest

Referer http://localhost:8080/MyApplication/

Content-Length 17

Cookie JSESSIONID=640868A479C40792F8AB3DE118AF12E0

Pragma no-cache

Cache-Control no-cache

Please guide me. What am i doing wrong?? HELP!!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值