Reputation: 2418
How do I notify the controller that the delete button was clicked?
MyController.php
public function actionUpdate($id)
{
isset($_POST['del'])
{
// delete user.
}
}
MyView.php
<?php
echo '<button type="button" class="btn btn-danger" name="deleteButton">Delete User</button>';
?>
This is what I tried:
$('.deleteButton').click(function()
{
var clickBtnValue = $(this).val();
var ajaxurl = Yii::app()->basePath . '/controllers/MyController.php';
del = {'action': clickBtnValue};
$.post(ajaxurl, del, function (response)
{
alert("action performed successfully");
});
});
But I can't receive the notice on the controller that the button was clicked.
Upvotes: 3
Views: 93
Reputation: 1997
$('.deleteButton')
selects element by class, not by name. $('[name="deleteButton"]')
should be used instead.<?=Yii::app()->basePath ?>
.<?=$this->createUrl('my/update', array('id' => $userId) ?>
. Lear more about url management.Upvotes: 2