1

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 ?

Tuấn Anh
  • 21
  • 6

1 Answers1

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
  • 14,821
  • 4
  • 48
  • 70
  • 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
  • @TuấnAnh how did you use it? State in your question – Hüseyin BABAL Mar 26 '14 at 17:08
  • 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