0
ajax関数を無効にするとフォームが正常に送信される理由を理解するのが難しいです。私は入力フォームでajaxを有効にします。入力値は入力されません。私は提出されているFormDataをチェックするためにクローム開発ツールを使用しました。何も提出されていないことに気づいた。 したがって、私はそれらのフィールドを埋めるように私に要求するエラーを取得します。JQueryとSpring Controllerを使用してフォームを送信する方法
<form method="post" th:object="${certificate}"
th:action="@{${action1}}" class="form-inline inline new-item editCert">
<input type="hidden" th:field="*{id}"/>
<div th:replace="common/layout :: flash"></div>
<div class="flash"></div>
<fieldset>
<legend th:text="${heading}"> Personal Information</legend>
<div class="row" th:classappend="${#fields.hasErrors('fullName')}? 'error' : ''">
<input type="text" class="form-control input-sm" th:field="*{fullName}"
placeholder="Full Name example Jane Doe"/>
<div class="error-message" th:if="${#fields.hasErrors('fullName')}" th:errors="*{fullName}"></div>
</div>
<div class="row" th:classappend="${#fields.hasErrors('gender')}? 'error' : ''">
<select th:field="*{gender}" class="form-control input-lg ">
<option value="">[Select Gender]</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<div class="error-message" th:if="${#fields.hasErrors('gender')}" th:errors="*{gender}"></div>
</div>
<div class="row" th:classappend="${#fields.hasErrors('date')}? 'error' : ''">
<input th:type="date" data-value="20/04/2015" class="form-control input-sm datepicker" th:field="*{date}"
placeholder="Date Of Birth"/>
<div class="error-message" th:if="${#fields.hasErrors('date')}" th:errors="*{date}"></div>
</div>
ajaxを有効にすると、フォームデータはおそらくjson形式で送信されます。 ajaxを無効にすると、データはフォームデータ形式で送られますので、コントローラを必要に応じて調整する必要があります。あなたのJqueryでは、e.preventDefault();を使用して送信を停止し、AJAXとしてデータを送信しているようですが、なぜそうするのですか? –
@zakariaamine私はdivにそのフォームをロードしているので、私はデフォルトの機能を妨げています。したがって、私はjQuery $。postまたは$、Jqueryの機能を使用して、フォームasyncを送信できます。もし私がそれをしなければ、私は望む機能を得られないでしょう。どのような場合でも、フォームがコントローラに送信していない理由ではありません – ADecker