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