Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 请求的资源不允许使用指定的HTTP方法(jquery POST到spring)_Spring Mvc - Fatal编程技术网

Spring mvc 请求的资源不允许使用指定的HTTP方法(jquery POST到spring)

Spring mvc 请求的资源不允许使用指定的HTTP方法(jquery POST到spring),spring-mvc,Spring Mvc,使用SpringMVC4 以下是我的jQuery POST通话: $.post("<c:url value="/class/addCourse" />/" + d.classID + "/" + d.courseID); 这是错误 以下是请求的标题 因为我使用的是Spring Security,所以帖子头中必须包含一个CSRF令牌。在页面上的隐藏字段中自动生成令牌。此AJAX请求可以工作: $.ajax({ type: "POST", url: "${pageCo

使用SpringMVC4

以下是我的jQuery POST通话:

$.post("<c:url value="/class/addCourse" />/" + d.classID + "/" + d.courseID);
这是错误

以下是请求的标题


因为我使用的是Spring Security,所以帖子头中必须包含一个CSRF令牌。在页面上的隐藏字段中自动生成令牌。此AJAX请求可以工作:

$.ajax({
    type: "POST",
    url: "${pageContext.request.contextPath}/class/addCourse/" + d.classID + "/" + d.courseID,
    beforeSend: function (xhr) {
        xhr.setRequestHeader('X-CSRF-Token', $("input[name=_csrf]").val());
    }
});

浏览器中的url是什么?@vivekpansara我已经更新了包含url的标题截图。您是否尝试过:
$.post(${pageContext.request.contextPath}/class/addCourse/“+d.classID+”/“+d.courseID”)相同的错误,但代码看起来更漂亮。你能发布你的表单吗?
$.ajax({
    type: "POST",
    url: "${pageContext.request.contextPath}/class/addCourse/" + d.classID + "/" + d.courseID,
    beforeSend: function (xhr) {
        xhr.setRequestHeader('X-CSRF-Token', $("input[name=_csrf]").val());
    }
});