-4

React Code

componentDidMount(){
    fetch('http://localhost:8080/ulearn/rest/course/getAll')
        .then(result=> {
            this.setState({items:result.json()});
        });}

When i tried making a rest api call from two different ports(react port is running on 8088 and my rest api port running on 8080) i get the following error

Guillaume
  • 10,463
  • 1
  • 33
  • 47
Vijay Rajagopal
  • 47
  • 1
  • 10
  • 3
    And of course, you are scared to do very basic googling to find out what CORS is and how to do it properly? Instead you take screenshot and post one more pointless question. Google your error first it would save you tons of time. – dfsq Dec 03 '16 at 12:34

1 Answers1

0

This is not a problem with React, but as the message in the console explains, a problem with CORS :

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated.1 A web page may freely embed images, stylesheets, scripts, iframes, videos.[2] Certain "cross-domain" requests, notably AJAX requests, however are forbidden by default by the same-origin security policy.

You should setup CORS on http://localhost:8080.

Guillaume
  • 10,463
  • 1
  • 33
  • 47