php后端接口无法跨域

已经在php接口文件中添加:

header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

然而前端调用接口请求数据时仍然报错:

Failed to load http://aaa.com/version?test=1: Redirect from 'http://aaa.com/version?test=1' to 'http://bbb.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ccc.com' is therefore not allowed access.

https://img1.mukewang.com/5c8f3e270001bd9306250149.jpg

https://img2.mukewang.com/5c8f3e2800019d5d07740178.jpg

湖上湖
浏览 725回答 3
3回答

慕虎7371278

你可以使用callback的方式去解决前端的跨域问题

胡子哥哥

你设置的 Access-Control-Allow-Origin 得看你的Response Headers有没有有些框架会覆盖你的设置 还要设置 Access-Control-Allow-Method: GET POST OPTIONS PUT

米琪卡哇伊

你header都没加上, *前面少个空格
打开App,查看更多内容
随时随地看视频慕课网APP