HTTP状态406.Spring MVC 3.2,jQuery,JSON

编程入门 行业动态 更新时间:2024-10-24 22:30:28
本文介绍了HTTP状态406.Spring MVC 3.2,jQuery,JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从spring mvc应用程序中的jquery Ajax调用获取JSON响应.当我在controller方法中看到调试语句时,该请求似乎很好.但是,我仍然看到HTTP 406错误(获取: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 :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 ajax.googleapis/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 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

本文发布于:2023-11-24 21:18:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   Spring   HTTP   jQuery   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!