1

I have to call one ajax request using angular JS $http.get method but it shows me error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

My method is

$http.get(url).success( function(response) {
   // some thing here
});

there is any way to set crossDomain: true in get method

3 Answers 3

4

There are following options:

  1. Use JSONP.
  2. Add 'Access-Control-Allow-Origin' : '*' on the server.
  3. Use Chrome with '--disable-web-security' flag.
Sign up to request clarification or add additional context in comments.

Comments

0

Hope you are not trying to call the get method by browsing a local html file. Try launching it via http-server and then you can even use jsonp

Comments

-1

You have to allow the cors:

.config(function($httpProvider){ 
    $httpProvider.defaults.useXDomain = true;
    $httpProvider.defaults.headers.common["Accept"] = "application/json";
    $httpProvider.defaults.headers.common["Content-Type"] = "application/json";
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

})

Comments

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.