虽然表单提交使用ajax..getting Post不支持错误...不知道是什么错误?

时间:2015-07-11 08:19:34

标签: ajax spring forms model-view-controller thymeleaf

我在Spring MVC和Thymeleaf中使用AJAX进行表单提交。当我尝试提交时,显示

  

不支持发布方法

我无法弄清楚代码中的错误:

<form class="form-horizontal" action="#" th:action="@{/teacher/teacherProfileUpdation}" th:object="${teacherProfileDetailsList}"
                         id="saveTeacherForm" method="POST" >
<br />
<div class="row">

    <div class="col-lg-14 col-md-12">
        <br />
        <h5 style="margin-left: 15%;">Personal Details</h5>
        <hr />
        <div class="form-group">
            <label class="col-sm-3 control-label">Name</label>
            <div class="col-md-3 col-sm-4 col-xs-4">
                <input placeholder="Teacher first name" id="txtTeacherFname" th:field="*{firstName}" type="text" class="form-control" />
            </div>
            <div class="col-md-3 col-sm-4 col-xs-4">
                <input placeholder="Teacher middle name" id="txtTeacherMname" th:field="*{middleName}" type="text" class="form-control" />
            </div>
            <div class="col-md-3 col-sm-4 col-xs-4">
                <input placeholder="Teacher last name" id="txtTeacherLname" th:field="*{lastName}" type="text" class="form-control" />
            </div>
        </div>

    </div>
    <div class="col-lg-14 col-md-12">
        <div class="form-actions">
            <input type="hidden" id="hdnStudentByIdInSchoolAdmin" value="0" /> 
            <input type="button" class="btn btn-info pull-right" id="btnUpdateTeacherProfile" value="Save" />
        </div>
    </div>
</div>

JS

saveTeacherProfile :function(){
    $("#saveTeacherForm").ajaxForm({
        success : function(status) { 
            alert("success");
        },
    }).submit();
}

控制器

@RequestMapping(value = "/updateTeacherProfile", method = RequestMethod.POST)
    public String updateTeacherProfile( TeacherProfileDetails teacherProfileDetails){

        System.out.println("-----------"+teacherProfileDetails.getFirstName()+"-------------");
        System.out.println("-----------"+teacherProfileDetails.getLastName()+"-------------");
        System.out.println("-----------"+teacherProfileDetails.getMiddleName()+"-------------");

        return "success";
    }

2 个答案:

答案 0 :(得分:0)

您正在发布表单,但很可能您的Spring控制器未配置为接受POST请求。在此页面的服务器端Controller类中尝试此操作:

@RequestMapping(..., method = { RequestMethod.GET, RequestMethod.POST }, ...)
public void myControllerMethod()
{

答案 1 :(得分:0)

@RequestMapping(...,method = {RequestMethod.GET,RequestMethod.POST},...) public String updateTeacherProfile(TeacherProfileDetails teacherProfileDetails){ //你的逻辑 }