Home Yii1: CGridView link ajax request shows 400 Bad Request
Reply: 0

Yii1: CGridView link ajax request shows 400 Bad Request

user1881
1#
user1881 Published in April 22, 2018, 10:03 pm

I am working on Yii 1 application. In my application, there is a CGridView where there is a link, which also fires an ajax request on onclick event. I am sending id as parameter. But the ajax return 400 Bad Request error. Please help me in this matter.

Here is the Gridview:

<h3>Civil Cases</h3>
<?php  $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'notifications-grid',
    'dataProvider'=>$dataProvider_civil,
    'summaryText' => false,

    'columns'=>array(
        array(
            'name' => 'case_id',
            'type' => 'raw',
            'value' => 'CHtml::link(CHtml::encode($data->case_id),array("civilcases/view","id"=>$data->case_id), array("onclick"=>"js:readNotification($data->id)"))'
        ),
        array(
            'name' => 'caseno',
            'type' => 'raw',
            'value' => 'CHtml::link(CHtml::encode($data->caseno),array("civilcases/view","id"=>$data->case_id), array("onclick"=>"js:readNotification($data->id)"))'
        ),
        'date_filing',
        'next_date',
        'panel_lawyer_id',

    ),
));
?>

here is the script:

<script>
    var readNotification = function(id) {
        console.log("button clicked with ID: "+id); //getting id here
        $.ajax({
            type:'POST',
            url:'<?php echo Yii::app()->createUrl("notifications/readNotification");?>',
            data: {id: id}
        });
    };
</script>

here is the controller:

public function actionReadNotification(){
    echo $_POST['id'];
}

added readNotification function to the accessRules. When clicking on the link new page is loading but ajax request shows error.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311747 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO