HTTP状态406.Spring MVC 3.2,jQuery,JSON [英] HTTP Status 406. Spring MVC 3.2, jQuery, JSON
问题描述
我正在尝试从spring mvc应用程序中的jquery Ajax调用获取JSON响应.当我在controller方法中看到调试语句时,该请求似乎很好.但是,我仍然看到HTTP 406错误(获取http://:8080/SampleFormEventInSpring/getData.html 406不可接受).我的设置如下.任何帮助都将受到高度赞赏
I am trying to get the JSON reponse from a jquery Ajax call in a spring mvc application. The request seems to fine as I see the debug statements in the controller method. However, I keep seeing the HTTP 406 error (GET http://:8080/SampleFormEventInSpring/getData.html 406 Not Acceptable). My setup is given below. Any help is highly appreciated
Spring 3.2
jackson-mapper-asl-1.7.4.jar
jackson-core-asl-1.7.4
Eclispe Juno Service Release 2
http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
响应标题
Content-Language en
Content-Length 1067
Content-Type text/html;charset=utf-8
Date Sun, 05 Oct 2014 01:06:16 GMT
Server Apache-Coyote/1.1
请求标头
Accept application/json
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cookie JSESSIONID=31E855326C016B194B0F013FEC470FAD
Host localhost:8080
Referer http://localhost:8080/SampleFormEventInSpring/event.html
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
X-Requested-With XMLHttpRequest
控制器代码
@RequestMapping(value = "/getData", method = RequestMethod.GET)
@ResponseBody
public List<Data> getProviderList() {
System.out.println("Inside EventController.getData Begin");
List<Data> dataList = new ArrayList<Data>();
Data pData = new Data();
pData.setId("0012M");
pData.setName("Group");
dataList.add(pData);
pData = new Data();
pData.setId("12345");
pData.setName("Individual");
dataList.add(pData);
for(Data iPdata : dataList) {
System.out.println("pID : " + iPdata.getId() + ",pNAME : " + iPdata.getName());
}
System.out.println("Inside EventController.getData End");
return dataList;
}
Data.java
Data.java
public class Data {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
JS
$(document).ready(function() {
$("#getData").click(function(){
$.ajax({
type:'GET',
url:'getData.html',
dataType: 'json',
success:function(data){
alert("Success");
}
});
});
推荐答案
我遇到了同样的问题
通过 jQuery 和 @RequestMapping 关于要使用的URL,编辑
From your jQuery and @RequestMapping about the URL to be used, edit
来自
-
getData.html
到
-
getData
是的,删除.html
扩展名.
此外:您有url:'getData.html',
和@RequestMapping(value = "/getData"
他们不匹配.
Furthermore: You have url:'getData.html',
and @RequestMapping(value = "/getData"
They does not match.
更改自
- `url:'getData.html'
到
- `url:'getData'
这篇关于HTTP状态406.Spring MVC 3.2,jQuery,JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!