js ajax 405,Ajax POST results in a 405 (Method Not Allowed) - Spring MVC

I'm trying to make an ajax call to my Spring controller/action with POST method, and return an object from the server with @ResponseBody. The strange situation is that it stop working after add spring security layer, everything was working fine before. I will try to explain my moves to solve the problem and then show you the code/captures/etc.

1.

After some research I found some answers telling the problem might be related with csrf mechanism, so I disabled it and still have the issue. (spring-security.xml bellow)

2.

I've made a wireshark capture to check the request/response. My ajax request is OK, my controller declaration is OK, but I don't understand why, the 405 response indicates > Allow: GET (capture bellow)

3.

I've tried to access my controller action through the browser (i.e., make an GET request), and I get the error HTTP Status 405 - Request method 'GET' not supported!

4.

I've tried to change the RequestMapping(method...) to RequestMethod.GET and the request arrives to the controller and works fine, but I don't want it to work on GET method, I want a POST request.

5.

Changed the RequestMapping(consumes, produces, headers) to accept all kind of data, but still 405...

This is driving me crazy! I post my files bellow, so you can check it guys, any tip will be appreciated. Thanks! (IMPORTANT NOTE: this is my despair configuration)

spring-security.xml

xmlns...(all needed declarations)>

username-parameter="email"

password-parameter="password"

authentication-failure-url="/login?failed" />

..... (authentication)

AdminController.java

@Controller

@RequestMapping("/admin**")

public class AdminController {

... (all my autowired beans)

@RequestMapping(

value = "/events/loadEvents",

method = RequestMethod.POST,

consumes = MediaType.ALL_VALUE,

produces = MediaType.ALL_VALUE,

headers = "Accept=*/*")

@ResponseBody

public Event loadEvents(@RequestParam("parentId") long parentId) {

... (my logic)

return event;

}

}

Request (wireshark capture)

TgsH8.jpg

Response (wireshark capture)

au3Tw.jpg

EDIT

jquery ajax call code

$.ajax({

type: 'POST',

cache: false,

url: /admin/events/loadEvents,

data: { parentId: 1 },

dataType = 'json',

contentType = 'application/json',

...

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值