org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported不支持请求方法'POST'

时间:2016-09-10 10:14:15

标签: javascript ajax spring-mvc post

我想将表单数据发送到我的控制器usign AJAX。低于我为此所做的尝试..

我的Javascript功能

<script>
      function masterRegistration(){


          $.ajax({
            type: "POST",
            url: "./masterRegistrationData",

            success: function(data){
                console.log("SUCCESS ", data);
            },
            error: function(e){
                console.log("ERROR ", e);
            }

        });
      }
</script>

我的控制器

@RequestMapping(value = "/masterRegistrationData", method = RequestMethod.POST )
   public String register(HttpServletRequest request) throws ParseException {

}

我不知道我哪里错了。我在控制器中低于错误

org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported 警告:不支持请求方法“POST”

请让我纠正..

1 个答案:

答案 0 :(得分:0)

试试这个并在浏览器开发者工具中检查网络标签,看看在进行ajax调用时生成了什么网址

<script>
  function masterRegistration(){
      var ctx = "${pageContext.request.contextPath}";

      $.ajax({
        type: "POST",
        url: ctx +"/masterRegistrationData",

        success: function(data){
            console.log("SUCCESS ", data);
        },
        error: function(e){
            console.log("ERROR ", e);
        }

    });
  }
</script>