2

I'm trying to do a quite simple task - getting the html content of a website with AngularJS. This is my code:

$http({method: 'GET', url: "http://www.google.com",
            headers:{
                'Access-Control-Allow-Origin': '*',
                'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
                'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
            }})
            .success(function(d){ console.log( "yay" ); })
            .error(function(d){ console.log( "nope" ); });

The problem is that I get the CORS error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I familiar with the CORS issue quite well, I know it's a server issue mainly. But still, can anyone suggest (if possible) a solution to my problem?

1 Answer 1

3

You are trying to make cross origin request to google.com. Google needs to accept your domain in order to do CORS. You do not have permission to do that action. Please look this documentation about CORS

The solution is to make a request to your backend service and let that service fetch the content and return it back to client side.

Sign up to request clarification or add additional context in comments.

2 Comments

Not sure your completely right. I know the server need to enable it, but how does this chrome extension does it - github.com/jeremys/Simple-Rest-Client-Chrome-Extension? From looking at the code it seems like he does xhr request, and by monitoring the network, there is no server call.
That is for package app. It is possible but not for hosted app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.