0

I have an angular 4 app talking to a php script that resides on WAMP (www folder) they are both on my local machine. I get this error logged in the browser when i hit the script.

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:4200' is therefore not allowed access. 
The response had HTTP status code 404.

I know its because i am trying to access from localhost to localhost that this problem occurs.

I did a bit of reading and it appears i need to fix it from wamp server. Not sure how to do that on wamp.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Joshua Majebi
  • 1,110
  • 4
  • 16
  • 34

2 Answers2

6

As commented, the problem is that you need to allow all origins from the script.

//at the very begining of your php script.
header('Access-Control-Allow-Origin: *'); 
yBrodsky
  • 4,981
  • 3
  • 20
  • 31
2

For me, I was trying the other answer, it did not work for some reason, but I try the one below and it worked:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Authorization, Origin');
header('Access-Control-Allow-Methods:  POST, PUT, GET');
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Hygison Brandao
  • 590
  • 1
  • 4
  • 16