Why is same origin policy kicking in when making request from localhost to localhost?

前端 未结 2 933
不思量自难忘°
不思量自难忘° 2020-12-11 05:32

I\'m keeping the backend API as a separate project from the frontend HTML5 app consuming it. I\'m using Yeoman for the frontend development. Yeoman runs on localhost:3501 an

2条回答
  •  醉梦人生
    2020-12-11 05:52

    According to W3C, "An origin is defined by the scheme, host, and port of a URL", so the different port is causing your problems.

    Two possible solutions:

    • CORS (Cross Origin Resource Sharing)
    • Using JSONP requests

    Both would require changes to your backend (I'm not familiar enough wo. CORS would probably mean the least changes to your frontend (I think AngularJS supports it out-of-the-box).

提交回复
热议问题