duangou1868 2016-05-29 20:46
浏览 68

跨源请求已阻止:同源策略禁止读取远程资源

I have found a sample Slim Api script that works fone when I run it on localhost - however when I upload API script to my website and try calling from localhost - I get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at         http://phoenixsoftware.co.nz/SocialProject/api/updates?_=1464554029519. (Reason: CORS header 'Access-Control-Allow-Origin' does not match '*, *').

I have updated the index.php API script to have a header as follows: header("Access-Control-Allow-Origin: *");

Also the .htaccess is as follows: RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the 
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用三极管设计—个共射极放大电路
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示