ArtMavir
@ArtMavir

Как в anglarjs выволнить http delete?

Здравствуйте. Не могу понять как выполнить запрос типа delete в angularjs. На сервере есть rest api, оно ждет два параметра на вход. Делаю так:
$http.delete('http://api/v1/contacts/index/', {params: {id_user: $localStorage.userAuthData.id_user, id_contact: id_contact}})
			.success(function(data)
			{
}
			});


но ничего не работает. После сериализации данных, они просто подставляются в url, но это по моему неправильно. Пожалуйста, подскажите.

P.S. На сервере codeigniter rest api.

Сам метод:
function index_delete()
	{
		$id_user = $this->delete("id_user");
		$id_contact = $this->delete("id_contact");

		if (!empty($id_user) && !empty($id_contact))
		{
			if ($id_user == $this->data_token->id_user)
			{
				$data_contacts = array(
					'id_user' => $id_user,
					'id_contact' => $id_contact
					);
				if ($this->contacts_model->delete_contact($data_contacts))
				{
					$data_response = array(
						'status' => 'success',
						'response' => $data_contacts
						);
					$this->response($data_response, 200);
				} 
				else 
				{
					$data_response = array(
						'status' => 'failed',
						'response' => 'Error delete contact.'
						);
					$this->response($data_response, 500);
				}
			}
			else 
			{
				$data_response = array(
					'status' => 'failed',
					'response' => 'User with the token does not exist.'
				);
				$this->response($data_response, 404);
			}
		}
		else 
		{
			$data_response = array(
				'status' => 'failed',
				'response' => 'Data were not obtained or is not valid.'
				);
			$this->response($data_response, 500);
		}
	}
  • Вопрос задан
  • 2379 просмотров
Решения вопроса 1
MAKAPOH
@MAKAPOH
многостаночник
Судя по документации angular всё делает правильно, т.к. передача тела для DELETE запроса не определена:

A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.

Принимайте ваши параметры из строки запроса на стороне сервера.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы