title: Jquery Ajax form not submitting and url is showing csrf token
body: <p>I'm sort of new to Ajax and I'm trying to submit a form using jquery, ajax and thymeleaf for the view. I know the post url works because if I just tell the ajax to submit as soon as the page loads whatever is in the form is submitted to the databse with no problem, but if I try to do it using a submit button, then the form goes blank, and the url changes to something like this <code>http://localhost:8080/viewCourse/post/1?_csrf=d512fb5c-08e5-4373-895e-1297b0c35a4b</code>, and nothing enters the database, yet there isn't an error in the console either, so I'm not sure what's happening.</p>
  
  <p>Here's my jquery and ajax</p>
  
  <pre><code>var postId = /*[[${post.id}]]*/'1';
  
  var token = $("meta[name='_csrf']").attr("content");
  var header = $("meta[name='_csrf_header']").attr("content");
  
  $(document).ajaxSend(function(e, xhr, options) {
      xhr.setRequestHeader(header, token);
  });
  
  $("#submit").click(function() {
      $.ajax({
          url : "newComment",
          type : "post",
          data : {
              "postId" : postId,
              "newComment" : $("#newComment").val()
          },
          success : function(data) {
              console.log(data);
              location.reload();
          },
          error : function() {
              console.log("There was an error");
          }
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>and here's my html using thymeleaf</p>
  
  <pre><code>&lt;div id="newCommentForm"&gt;
      &lt;form&gt;
          &lt;div class="form-group"&gt;
              &lt;textarea rows="2" id="newComment" placeholder="comment"
                        class="form-control" style="width: 520px;"&gt;
              &lt;/textarea&gt;
          &lt;/div&gt;
          &lt;input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/&gt;
          &lt;input type="submit" value="Comment" id="submit" class="btn btn-info"/&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If anyone can see what I'm doing wrong and let me know that would be great, thanks in advance.</p>