简体   繁体   中英

How to cross domain by javascript?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM