That is the same code that the CButtonColumn delete button uses, and I am calling the same delete function in my controller.
public function actionDelete($id)
// we only allow deletion via POST request
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
The problem is that when I try to use my custom delete button, the action throws the exception saying it is not a POST request.
So how could I make my button work so it calls the action using POST/Ajax ?
The problem is that I don’t understand ajax. I imagine I have to write something similar using registerscript. Maybe someone who understands better how this ajax thing works could share the code to make the button call the function using ajax. Also, if there a link where I could learn more on how to use those strange ajax functions that start with “$.” I would really appreciate it.
Of course the easiest thing would be to give you the code that works but as you say you don’t understand nor even know how or what it does, in my opinion it’s better for you to learn first a bit about jQuery so you can understand what that code does.
So, for what I understand what that js script does is to stop the link and instead call the function (in this case the .fn.yiiGridView.update() function). One of the things I do not understand is why ".fn.yiiGridView.update"? I am guessing that the function not only does the ajax call but updates the data in the grid. But how someone is supposed to find out the .fn.yiiGridView.update function name? I can not find it in the yii documentation (or maybe I am not looking in the right place).