No ‘Access-Control-Allow-Origin’ in ajax request, but not by clicking on a <a> tag link

I am using HapiJS and Bell to authenticate users. I have an endPoint that is responsible to authenticate the users.

  server.route({
    method: ['POST','GET'],
    path: '/token',
    config: {
      auth: 'twitter',
      handler: function (request, reply) {

       reply(request.auth.credentials.profile)

      }
    }
  });

When I have an <a> tag link pointing to that endPoint everything works well, I am redirecting to twitter to authenticate and then I see the reply. What I want is to make that through ajax request so I can handle the response using then.

So I have something simple:

$.ajax({
  method: 'GET',
  url: 'http://localhost:8001/token'
}).then(function(data){
  console.log('>>>>>>>>>',data);
});

I click a button and I make the request, but in this case I have the following message on Chrome XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=TPSmxB22abgI2jC8DvEgUxKOc4ZadsSI. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. Any idea how can I solve that?


Source: ajax

Leave a Reply