0

I am experimenting with some web programming. I wrote a python API that will make a query to an SQL database and return a JSON. The API works as expected.

On the other hand, I have a controller where I make the GET request to use the JSON.

The GET request is made and the API gets rolling; however, when the API returns the JSON the following appears in the developer console of the browser:

Failed to load http://localhost:3000/api/s1r2_rep_fis: No 'Access- Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:8000' is therefore not allowed access.

I guess this is due to permissions. My http server is run by python:

python -m http.server

The controller code is:

app.controller("test", function($scope, $http){
    $http.get("http://localhost:3000/api/s1r2_rep_fis")
    .then(function(response){
        $scope.Clientes = response.data;
    });
});

Please forgive me if I mix up some terms/technology, this is my first time using html/javascritp/angularJS.

Any help will be deeply appreciated

6
  • has nothing to do with the backend call, you are making a call to a different domain Commented May 11, 2018 at 1:15
  • @epascarello what do you mean to a different domain? Commented May 11, 2018 at 1:20
  • stackoverflow.com/questions/21854516/… Commented May 11, 2018 at 1:20
  • My guess is you are loading html page from one port and the python code in another Commented May 11, 2018 at 1:21
  • @epascarello you are correct, the API is listetint con localhost:3000 and the server runsin localhost:8000. If I change the API port to 8000 I get an error saying that the Address is already in use. Commented May 11, 2018 at 1:33

1 Answer 1

0

From my understanding, this is a server-side issue. Not client side. All you need to do is to add CORS enable header on your server.

Access-Control-Allow-Origin: *

You can also check here how to enable CORS.

enable-cors.org

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

1 Comment

I think I get it now, I tried to use this: stackoverflow.com/questions/21956683/…, however id did not work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.