title: The CSRF token in Yii 1 could not be verified for an AJAX request
body: <p>I have enabled <code>csrfToken</code> in Yii 1 and it works fine with simple post request. But whenever I have AJAX request it fails. I used the below code:</p>
  
  <p>main.php</p>
  
  <pre><code>'components' =&gt; array(
      'request' =&gt; array(
          'enableCsrfValidation' =&gt; true,
      ),
  ),
  </code></pre>
  
  <p>I found it for ajax request solution from one wiki article but this not worked</p>
  
  <p>Controller.php</p>
  
  <pre><code>public function init() {
          parent::init();
          $this-&gt;initAjaxCsrfToken();
      }
  
      // this function will work to post csrf token.
      protected function initAjaxCsrfToken() {
  
          Yii::app()-&gt;clientScript-&gt;registerScript('AjaxCsrfToken', ' $.ajaxSetup({
                           data: {"' . Yii::app()-&gt;request-&gt;csrfTokenName . '": "' . Yii::app()-&gt;request-&gt;csrfToken . '"},
                           cache:false
                      });', CClientScript::POS_HEAD);
      }
  </code></pre>
  
  <p>I need a global solution.</p>