title: How to pass along CSRF token in an AJAX post request for a form?
body: <p>I'm using Scala Play! 2.6 Framework, but that may not be the issue. I'm using their Javascript routing - and it seems to work ok, but it's having issues. I have a form, which when rendered produces this, with a CSRF token:</p>
  
  <pre><code>&lt;form method="post" id="myForm" action="someURL"&gt;
  
  &lt;input name="csrfToken" value="5965f0d244b7d32b334eff840...etc" type="hidden"&gt;
    &lt;input type="text" id="sometext"&gt;
    &lt;button type="submit"&gt; Submit! &lt;/button&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And here's roughly, my AJAX:</p>
  
  <pre><code>$(document).on('submit', '#myForm', function (event) {
  
   event.preventDefault();
     var data = {
      textvalue: $('#sometext').val()
     }
   var route = jsRoutes.controllers.DashboardController.postNewProject()
   $.ajax({
      url: route.url,
      type: route.type,
      data : JSON.stringify(data),
      contentType : 'application/json',
      success: function (data) { ...      },
      error: function (data) { ...  }
          })
  
  });
  </code></pre>
  
  <p>But when I post this, I am getting an UNAUTHORIZED response back from my Server, and my console in IntelliJ is telling me the CSRF check is failing. How would I pass along the CSRF token in the request?</p>