$.ajax Post Return Error 400 Bad Request


I have this controller function generated by gii

	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.');


I need to call this function in javascript and my js code is



	url: "/people/delete",

	type: "post",

	data: { YII_CSRF_TOKEN: $("#YiiCsrf").val(), id: $(this).attr("name") },

	success: function(response, textStatus, jqXHR)




	error: function(jqXHR, textStatus, errorThrown)


		alert(jqXHR.status + ' ' + textStatus + ' - ' + errorThrown);


	complete: function()




I got error 400 Bad Request. Anything wrong?

I may be completely wrong, but I believe only GET data is passed into the action’s parameters by default. This thread may point you in the right direction:


Keith is completely right :)

I have changed to use type: "get" and modify the actionDelete to accept get request.

Thanks all.

That’s a bad practice.

Delete should be done via POST (or DELETE).

Just change this line

url: "/people/delete",


url: "/people/delete/id/" + $(this).attr("name"),