Difference between $http.get and method:'GET'

五迷三道 提交于 2019-12-10 19:21:41

问题


I'm using Spring Data REST and have a MySQL DB to manage my data. With AngularJS I programmed my first page and want to get data from my DB.

To get my data I know about two different ways:

$http.get('http://myURL')

and

$http({
    method:'GET'
    url:'http://myURL'
}

But where's the difference between them?

Thanks for help!


回答1:


There is no difference, $http.get('http://myURL') is just a shortcut for $http({method:'GET, url:'http://myURL'}




回答2:


  1. First way of getting the response is the short form of the second one.

  2. If you want to set some headers for the request you have to write the request via second way... that is much more clear way of writing it.

    var req = { method: 'POST', url: 'http://example.com', headers: {       'Content-Type': undefined },  data: { test: 'test' }} $http(req).then(function(){...}, function(){...});
    



回答3:


$http.get('url') is just the shorthand notation of writing $http({method:'GET ',url:'url '})

Its same as jQuery is the shorthand notation for JavaScript

If you want to modify header in the api call,use second notation



来源:https://stackoverflow.com/questions/37859585/difference-between-http-get-and-methodget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!