title: Yii2 ajax bad request (#400)
body: <p>When I use this code, I get this error as a response:    </p>
  
  <blockquote>
    <p>Bad Request (#400): Not possible to verify your data</p>
  </blockquote>
  
  <pre><code>/**
   * Active toggle
   */
  $(document).on('click', '[data-toggle-active-menu-items]', function(e){
  
      e.preventDefault();
  
      var id = $(this).data('toggle-active-menu-items');
  
      $.ajax({
          url: 'active',
          type: 'POST',
          data: {'id': id, _csrf: yii.getCsrfToken()}, 
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(data) {
              if (data.active == 1)
              {
                  $('#list-' + id + ' [data-toggle-active-menu-items]').html('&lt;span class="glyphicon glyphicon-eye-open"&gt;&lt;/span&gt;');
              } else {
                  $('#list-' + id + ' [data-toggle-active-menu-items]').html('&lt;span class="glyphicon glyphicon-eye-close"&gt;&lt;/span&gt;');
              }
          }
      });
  });
  </code></pre>
  
  <p>I tried adding  </p>
  
  <blockquote>
    <p>_csrf: yii.getCsrfToken()</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>contentType: "application/json; charset=utf-8",<br>
            dataType: "json",</p>
  </blockquote>
  
  <p>but that's not working</p>
  
  <p>it does work when I add this to my controller, but that's no good, I don't want to disable csrf validation</p>
  
  <blockquote>
    <p>public $enableCsrfValidation = false;</p>
  </blockquote>
  
  <p>How can I fix this?</p>