Doubt $http Angularjs

Asked

Viewed 61 times

0

I have a form where some inputs will be used to make a filter, but as there are many, not need to pass the fields via GET this way: Ex: ? filtro1=teste&filter 2=teste2 ..., can I use the $http.post method from Angularjs without any problems ? It’s wrong to use it that way ?

  • These are different approaches. You can do it, you can! But the decision between using a GET or a POST goes beyond the decision to just work!

  • Exactly Murilo, so my doubt, if it is a correct approach, it works perfectly but I do not know if it is correct.

  • There is no mistake.

2 answers

2


There is no problem in using the POST method instead of GET. This method is safer and has a better data capacity than GET. In this method a parallel connection is opened and the data is passed through it. There is no size restriction (However this size can be limited if you want, just make this small configuration on the server: php_value post_max_size 20M), in addition the data is not visible to the user.

The GET method, on the other hand, is recommended when you want to pass little/little information to perform a search or simply pass information to another page through the URL (address bar).

What cannot happen is your requests result in changes in the content of the answer. The function of the GET method is to simply recover an existing resource on the server, if you use it to alter data, you will be making misuse and opening security loopholes.

The result of a GET request is "cacheable" by the client, that is, it is in the browser history.

Give this one a read sopt’s question, which has more interesting details for you to know.

0

Guilherme, as quoted by @Murilomittmann, it is possible to do yes, but it was not made for this, the ideal is to use GET.

The http protocol describes that GET should be used to request resources, so that this request does not change the status of the server, so multiple requests in sequence can occur without causing problems.

Regarding the POST, the protocol describes that it is for submitting forms or sending information for processing that will possibly lead to a change in server status.

Therefore, philosophically the correct would be to use GET.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.