简体   繁体   English

Spring MVC控制器不会拦截Ajax POST

[英]Spring MVC controller does not intercept Ajax POST

I have a javascript function: 我有一个javascript函数:

var RestPost = function() {
    $.ajax({
        type : 'POST',
        url : '/bollo/search/details',
        dataType : 'json'
    });
};

and a controller setted on the same url 和设置在相同网址上的控制器

@RestController
@RequestMapping(value = "/bollo/search/details")
public class BolloRestController
{
    @RequestMapping(method = RequestMethod.POST)
    public String details()
    {
        System.out.println("method reached");
        return "bollo/ricerca_bolli.html";
    }
}

I've searched on many sites, with many examples, but I do not really get what I did wrong because the URL is the same and the request methond either. 我在许多站点上搜索了很多示例,但是我并没有真正弄错我做错了什么,因为URL相同,请求也是如此。

Debugging the code in Chrome's console it always get the same error: 在Chrome控制台中调试代码总是会得到相同的错误:

POST http://localhost:9080/bollo/search/details 404 (Not Found) POST http:// localhost:9080 / bollo / search / details 404(未找到)

Does anyone know why? 有人知道为什么吗?

AppContextRootName: Your application context root AppContextRootName:您的应用程序上下文根

var RestPost = function() {
        $.ajax({
            type : 'POST',
            url : '/AppContextRootName/bollo/search/details',
            dataType : 'json'
        });
    };

Add the Project Name in URL with /bollo/search/details it won't give 404 error then. 使用/ bollo / search / details在URL中添加项目名称,这样就不会出现404错误。

Like if you made the web project with name SpringWS then use SpringWS/bollo/search/details to trigger the Ajax request. 就像如果您使用名称为SpringWS的Web项目进行创建一样,请使用SpringWS / bollo / search / details触发Ajax请求。 Here is my case port is 8085. 这是我的情况下端口是8085。

<script>
var RestPost = function() {
    $.ajax({
        type : 'POST',
        url : 'http://localhost:8085/SpringWS/bollo/search/details',
        dataType : 'json'
    });
};
RestPost();
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM