0

My goal was to have off a form submit for a get to be performed and as part of the uri, key value pairs appended like the following: // GET /pets/42;q=11;r=22 Reading http://www.w3schools.com/tags/att_form_method.asp description of form with setting form method to "get" I would have thought this was possible. In the world of angular, it seems like the expected behavior for a submit of a form results in post method. The controller can be written to generate any http verb but has the $http.get doesn't do what plain form get method would automatically and to generate a url like above, the controller would have to build the uri itself. My apprehension of always using post off a form submit was the form in this case was part of a query/search action and not a data creation exercise. Maybe that's not the proper way to use form but has angular done away with automatically appended values from controls in key value pairs for a form with the $http.get service?

Michael Sampson
  • 369
  • 1
  • 6
  • 19
  • In normal circumstances, when the form method is GET and the user submits the form, the URL changes to reflect the action attribute in the form - am I correct? I can answer based on this... – callmekatootie Aug 24 '15 at 14:24

1 Answers1

0

Of course you can do GET with query params in url.

The easiest way is to pass an object representing the key/value pairs to the params property of the $http config object.

var params = {q: 11, r:22};
$.get('/path/to/server/', {params: params}).then(....

Alternatively you can also create your own url string when you only have small number of params.

For further details read through the Usage section of $http docs

charlietfl
  • 170,828
  • 13
  • 121
  • 150