Hi,
I have this controller function generated by gii
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
I need to call this function in javascript and my js code is
$.ajax
({
url: "/people/delete",
type: "post",
data: { YII_CSRF_TOKEN: $("#YiiCsrf").val(), id: $(this).attr("name") },
success: function(response, textStatus, jqXHR)
{
alert(response);
},
error: function(jqXHR, textStatus, errorThrown)
{
alert(jqXHR.status + ' ' + textStatus + ' - ' + errorThrown);
},
complete: function()
{
}
});
I got error 400 Bad Request. Anything wrong?