title: Yii Manual Ajax Post
body: <p>I am trying to manually send a ajax post request. I keep getting a "400 Bad Request". I am using yii 1.1.x on my localhost.</p>
  
  <p>Here is my view:</p>
  
  <p>view admin.php</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function findDealerSettings(did){
                  alert(did);
                  $.ajax({
                          type: 'POST',
                          url: '/dealers/ajaxDs',
                          data: did,
                          success: function (data) {
                                  alert("Made it");
                          }
                  });
          }
  &lt;/script&gt;
  
  &lt;?php 
  $this-&gt;widget('zii.widgets.grid.CGridView', array(
          'id'=&gt;'dealers-grid',
          'dataProvider'=&gt;$model-&gt;search(),
          'filter'=&gt;$model,
      'template' =&gt; '{summary}{pager}{items}{pager}{summary}',
      'columns'=&gt;array(
                  'name',
                  'address1',
                  'city',
                  'state',
                  'phone',
                  array(
                          'header'=&gt;Yii::t('multi', 'Settings'),
                          'htmlOptions' =&gt; array('class' =&gt; 'button-column'),
                          'type'=&gt;'raw',
                          'value'=&gt; function($data) {
                                          return '&lt;a onclick="findDealerSettings('.$data-&gt;did.');$(&amp;quot;#mydialog&amp;quot;).dialog(&amp;quot;open&amp;quot;); return false;" class="settings" title="Update Setting" href="#"&gt;&lt;img src="/images/gear_sm.png" alt="Update Setting"&gt;&lt;/a&gt;';
                                  }
                  ),
  
                  array(
                          'class'=&gt;'EButtonColumnWithClearFilters',
              'label'=&gt;Yii::t('multi', 'Clear Search'),
          ),
  
          ),
  )); 
  ?&gt;
  </code></pre>
  
  <p>Controller - DealersController.php:</p>
  
  <pre><code>    public function accessRules()
      {
              return array(
                      array('allow', // allow dealerSettings user to perform 'manage' action
                              'actions'=&gt;array('manage'),
                              'roles'=&gt;array('dealersettings')
                      ),
          array('allow', 'actions'=&gt;array('dealercontextswitch'), 'roles'=&gt;array('authenticated')),
                      array('allow', // allow admin user to perform 'admin' and 'delete' actions
                              'actions'=&gt;array('admin','delete', 'create', 'view', 'update', 'ajaxDs'),
                              'roles'=&gt;array('admin'),
                      ),
                      array('deny',  // deny all users
                              'users'=&gt;array('*'),
                      ),
              );
      }
  
  ...
  
  
      public function actionAjaxDs(){
              if (!YII_DEBUG &amp;&amp; !Yii::app()-&gt;request-&gt;isAjaxRequest) {
                      throw new CHttpException('403', 'Forbidden access.');
              }
              echo "Made it";
  
      }
  </code></pre>
  
  <p>I had to add the accessRules for ajaxDs in order to access ajaxDs</p>
  
  <p>From this code I am able to use js to alert the did. After that I get a 400 Bad Request error for <a href="http://localhost/dealers/ajaxDs" rel="nofollow">http://localhost/dealers/ajaxDs</a></p>
  
  <p>When I actually go to <a href="http://localhost/dealers/ajaxDs" rel="nofollow">http://localhost/dealers/ajaxDs</a> I get a page that says "Made it", Like it is supposed to.</p>
  
  <p>I do not know why my ajax is not work. </p>
  
  <p>How do I manually enter in an ajax url for yii</p>
  
  <p>Any Help would be greatly appreciated! </p>
  
  <p>**************EDIT*****************</p>
  
  <p>If I remove the type: 'POST' it works</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          aXDS = '&lt;?php echo Yii::app()-&gt;createUrl('/dealers/ajaxDs'); ?&gt;';
  
          function findDealerSettings(did){
                  alert(did);
                  $.ajax({
                          //type: 'POST',
                          url: '/dealers/ajaxDs',
                          data: did,
                          success: function (data) {
                                  alert("Made it");
                          }
                  });
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm not sure why, and I need to post the data</p>