我找到了一个示例Slim Api脚本,当我在localhost上运行它时会运行 - 但是当我将API脚本上传到我的网站并尝试从localhost调用时 - 我收到以下错误:
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 '*, *').
我已经将index.php API脚本更新为具有如下标题: 标题(" Access-Control-Allow-Origin:*");
.htaccess也如下: 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]