I have API wirte by PHP in address: x I have UI wirte by html, js, css... in address: y In address y, in javascript code, I request to address x to get data then Chrome message in control: XMLHttpRequest cannot load 'x'. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'y' is therefore not allowed access How to resolve ?
Asked
Active
Viewed 102 times
1
-
Your primary focus here should be on [CORS](https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS). Does your data happen to be in JSON format? – Sampson Mar 26 '14 at 14:14
-
I would use a proxy on "address y" – davidkonrad Mar 26 '14 at 14:14
-
http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains – Charaf JRA Mar 26 '14 at 14:18
1 Answers
1
You need to give ;
header('Access-Control-Allow-Origin: x');
On your api in y
domain for domain x
. Above code means Allow "Access-Control-Allow-Origin" for domain x on y server

Hüseyin BABAL
- 15,400
- 4
- 51
- 73
-
You can explane me more detail ?. I set down vote accept You need to give ; header('Access-Control-Allow-Origin: x'); in code PHP in API server or Js in y server ? – Tuấn Anh Mar 26 '14 at 15:24
-
In order to make ajax request to server y from x, you need to set header `Access-Control-Allow-Origin` for client domain (x). You cannot make ajax request to different domain, it is blocked according to CORS. In order to make request, you need to allow on y server fo x – Hüseyin BABAL Mar 26 '14 at 15:31
-
It goes between servers, but OP are using XMLHttpRequest, that means it runs on the client, and **not** "server x". – davidkonrad Mar 26 '14 at 15:56
-
i still can not get data :( can you use TeamView and give me resolution – Tuấn Anh Mar 26 '14 at 16:27
-
-
download and install teamview here: http://www.teamviewer.com/en/index.aspx?pid=google.tv.s.int&gclid=CJDF9u_hsL0CFSVU4godrHUA9Q then I send to you my ID and my Password. You use it to login to my PC, then you can write code to solve my problem – Tuấn Anh Mar 26 '14 at 17:53