我正在尝试使用jQuery更新字符串数组。服务器是引导Spring MVC服务器。当我执行POST时,服务器的响应为HTTP 403 Forbidden
。
Spring 控制器
@RequestMapping(value="getlistmap", method = RequestMethod.POST) public @ResponseBody String getListMapfromOneProject(HttpServletResponse response, Principal p,@RequestBody String respostas) throws IOException { System.out.println("A AJAX call has been detected!"); return "ok!"; }
POST 代码:
来自服务器的var respostas=["hello","hi","bye"]; var urlprova = 'getlistmap'; $.ajax({ type: 'POST', url: urlprova, dataType: 'json', data: JSON.stringify(respostas), success: function (data) { alert("updated successfully"); }, error: function (xhr, ajaxOptions, error) { alert(err.status); alert('Cannot update, ' + err.responseText); }
});
控制台(URL和方法控制器似乎已正确映射):
2014-11-20 18:44:53.427 INFO 6724 --- [main] oswshandler.SimpleUrlHandlerMapping:将URL路径[/]映射到[class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]类型的处理程序上2014-11-20 18:44:53.466 INFO 6724 --- [main] swsmmaRequestMappingHandlerMapping:映射“{[/ login],methods = [GET],params = [],headers = [],consume = [], produce = [],custom = []}“on public org.springframework.web.servlet.ModelAndView palmaslab.mapas.controller.myController.login() 2014-11-20 18:44:53.466 INFO 6724 - - [main] swsmmaRequestMappingHandlerMapping:映射“{[/ getlistmap],methods = [POST],params = [],headers = [],consumes = [],produce = [],custom = []}”on public java .lang.String palmaslab.mapas.controller.myController.getListMapfromOneProject(javax.servlet.http.HttpServletResponse,java.security.Principal,java.lang.String)抛出java.io.IOException 2014-11-20 18 :44:53.467 INFO 6724 --- [main] swsmmaRequestMappingHandlerMapping:Mapped“{[/ addProjectPostoSaude],methods = [GET],params = [],headers = [],consume = [],produce = [],custom = []}“on public org.springframework.web.servlet.ModelAndView palmaslab.mapas。 controller.myController.addProject()
答案 0 :(得分:0)
您的ajax帖子看起来确实包含sessionId或用户凭据。 - 当您使用Spring Security时,您需要在每次请求时发送它们。
答案 1 :(得分:0)
一般看起来合法,尝试跟随,其中一个可能会解决您的问题:
@RequestMapping(value="/getlistmap"...
contentType: 'application/json'