I
I
Ilya2015-03-10 17:29:15
Angular
Ilya, 2015-03-10 17:29:15

How to execute http delete in angularjs?

Hello. I can't figure out how to execute a delete type request in angularjs. The server has a rest api, it waits for two input parameters. I do it like this:

$http.delete('http://api/v1/contacts/index/', {params: {id_user: $localStorage.userAuthData.id_user, id_contact: id_contact}})
      .success(function(data)
      {
}
      });

but nothing works. After serializing the data, they are simply substituted into the url, but this is wrong in my opinion. Please tell me.
PS On the codeigniter rest api server.
The method itself:
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);
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Алексей, 2015-03-10
@ArtMavir

Судя по документации angular всё делает правильно, т.к. передача тела для DELETE запроса не определена:
Принимайте ваши параметры из строки запроса на стороне сервера.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question