title: How to add csrf token to ajax request
body: <p>I have issues adding csrf to ajax request. I'm using thymeleaf on client side with spring-boot/spring security. Spring security wouldn't allow the request because csrf-token is missing.  Here is my code for ajax</p>
  
  <pre><code>function bits(){
      var xhttp = new XMLHttpRequest();
      var selected = document.getElementById("product").value;
      xhttp.onreadystatechange = function(){
        if(xhttp.readyState==4 &amp;&amp; xhttp.status==200){
          var result= JSON.parse(xhttp.responseText)
          var length = result.length;
          for(i=0; i&lt;length; i++){
  
             console.log(result[k].spid);
          }
      }
  
  };
  
   xhttp.open("POST", "http://localhost:8080/bids?q="+selected,  true);
   xhttp.send();
  </code></pre>
  
  <p>}</p>
  
  <p>Help will be appreciated</p>