How Do $Data->Id Transmit To The Js Code In Cgridview?

I have the code




$.get("/message/delete/", {"id":id});



I need




$.get("/message/delete/", {"id":$data->id});



but this code don’t work. I tried to use many different way. But I didn’t find good solving.

Does it perhaps?


$.get("/message/delete/", {"id": <?= $data->id ?>});

or even


$.get("/message/delete/", {"id": "<?= $data->id ?>"});

if your ids are not numeric.

PS. Do not use GET requests for deleting, use POST instead.

id is numeric





      'delete_' => array(

      'visible' => '$data->getVisible()',

      'label' => 'Delete',

//    'url' => '/message/delete',

      'options' => array(

      'onclick' => '$.post("/message/delete/", {"id": "<?= $data->id ?>" });',



answer out action delete


var_dump($_POST);


'id' => string '<?=  $data->id ?>' (length=15)

Oops, I’ve missed that you’re using CGridView.

Have you tried this? {$data->id}

Yes, I didn’t get any result, even in feedback


string '$data->id'

Have you tried to view source code in browser? The following line:


      'onclick' => '$.post("/message/delete/", {"id": "<?= $data->id ?>" });',

returns what?

browser returns this string




<?= $data->id ?>



It means that the code is not understood by the browser, try then:




      'onclick' => '$.post("/message/delete/", {"id": "<?php echo $data->id; ?>" });',



result is the same string


<?php echo $data->id; ?>

Upload your code more and I’ll have a look then :)