Answers.Body: <p>For Craft 2, these are the values you're looking for...</p>
  
  <pre class="lang-js prettyprint-override"><code>window.csrfTokenName = "{{ craft.config.get('csrfTokenName') }}";
  window.csrfTokenValue = "{{ craft.request.getCsrfToken }}";
  </code></pre>
  
  <p>They changed slightly in Craft 3, which can be seen <a href="https://craftcms.stackexchange.com/a/6588/45">here...</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-04T16:47:55.180Z
Answers.Text: Hey thank you so much, I was able to get the token name and value now. I'm still getting the 400 error even after adding this to the array I'm passing in the ajax request. I'm adding it like this: data[window.csrfTokenName] = window.csrfTokenValue;
Answers.UserDisplayName: WTFranklin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-04T22:01:19.240Z
Answers.Text: Hmm, not sure why you'd still be getting a 400. I'd recommend popping over to [Craft Discord](https://craftcms.com/discord), where it'll be easier to discuss the issue in greater detail.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T00:45:03.370Z
Answers.LastActivityDate: 2019-03-02T00:45:03.370Z
Answers.UserDisplayName: Lindsey D
Body: <p>I'm having an issue with Craft 2.6 and the CSRF token. I enabled Csrf Protection in my general.php file by adding this line $config['*'] array so it looks like:</p>
  
  <pre><code>$config['*'] = [
  ...
      'enableCsrfProtection' =&gt; true,
  ...
  ],
  </code></pre>
  
  <p>I also tried adding this line to the section for // Global variables after this array, but still no luck. I try to attach the token to the window object like this:</p>
  
  <pre><code>&lt;script&gt;
          window.csrfTokenName = "{{ craft.config.csrfTokenName }}";
          window.csrfTokenValue = "{{ craft.request.csrfTokenValue }}";
  &lt;/script&gt;
  </code></pre>
  
  <p>and the <code>window.csrfTokenName = "CRAFT_CSRF_TOKEN";</code> but <code>window.csrfTokenValue = "";</code> </p>
  
  <p>I can't figure out how else to get a csrf token and I can't find any documentation that says anything else. I'm just trying to see if I'm missing something really easy or if there is actually something else I need to add. Any help is greatly appreciated!</p>
  
Tags: <ajax><craft2><csrf>
Title: CSRF token is null or empty in craft 2
ThreadText: # CSRF token is null or empty in craft 2
  
  (Asked by: username_0 on 2019-03-02)
  
  I'm having an issue with Craft 2.6 and the CSRF token. I enabled Csrf Protection in my general.php file by adding this line $config['\*'] array so it looks like:
  
  ```
  $config['*'] = [
  ...
      'enableCsrfProtection' => true,
  ...
  ],
  
  ```
  
  I also tried adding this line to the section for // Global variables after this array, but still no luck. I try to attach the token to the window object like this:
  
  ```
  <script>
          window.csrfTokenName = "{{ craft.config.csrfTokenName }}";
          window.csrfTokenValue = "{{ craft.request.csrfTokenValue }}";
  </script>
  
  ```
  
  and the `window.csrfTokenName = "CRAFT_CSRF_TOKEN";` but `window.csrfTokenValue = "";`
  
  I can't figure out how else to get a csrf token and I can't find any documentation that says anything else. I'm just trying to see if I'm missing something really easy or if there is actually something else I need to add. Any help is greatly appreciated!
  
  **Tags:** ajax, craft2, csrf
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-02. Score: 2
  
  For Craft 2, these are the values you're looking for...
  
  ```js
  window.csrfTokenName = "{{ craft.config.get('csrfTokenName') }}";
  window.csrfTokenValue = "{{ craft.request.getCsrfToken }}";
  
  ```
  
  They changed slightly in Craft 3, which can be seen [here...](https://craftcms.stackexchange.com/a/6588/45)
  
  > **Comments:**
  > **username_0**: Hey thank you so much, I was able to get the token name and value now. I'm still getting the 400 error even after adding this to the array I'm passing in the ajax request. I'm adding it like this: data[window.csrfTokenName] = window.csrfTokenValue;  
  > **username_1**: Hmm, not sure why you'd still be getting a 400. I'd recommend popping over to [Craft Discord](https://craftcms.com/discord), where it'll be easier to discuss the issue in greater detail.  
  
  ---
  
  