Search code examples
javascriptangularjsnode.jshttptwitter-oauth

What is the fundamental difference between an anchor tag and a $http.get?


I'm making a web app using angular, and I was wondering what the difference was when I click an a tag like so...

<a href="/auth/twitter" target="_self" class="btn btn-primary">Login with Twitter OAuth</a>

compared to clicking a button that fires a function in my services.

$http.get('/auth/twitter')

The latter causes a No 'Access-Control-Allow-Origin' error and the first doesn't. So there's something different between them but I can't figure out or search what it is.


Solution

  • You should use $http.get for API/AJAX calls and the anchor for redirections.

    The reason is because an $http.get is expecting a result that is returned by the URL, like raw JSON data, and anchor not.

    Since you only need a redirection, you can't use the $http.get method and should use an anchor.