【发布时间】:2015-01-30 00:30:38
【问题描述】:
更新: 出于某种原因,服务器端脚本有 Unicode 字符,当我通过记事本保存它时,它切换到 ANSII 并且工作正常。我不确定 Unicode 的东西是如何进入那里的,但现在它正在工作。希望这篇文章能在未来对某人(很可能是我)有所帮助。
尽管我有正确的标题,但我收到了 CORS 错误。这是一个月前的工作,我的服务器或客户端代码没有任何改变。
服务器端
<?php
header('Access-Control-Allow-Origin: https://mywebsite.com');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
header('Access-Control-Allow-Credentials: true');
客户端错误
XMLHttpRequest cannot load https://serverside.com/serversidecode.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mywebsite.com' is therefore not allowed access.
服务器端代码完全运行,但不会将成功数据发送回我的客户端服务器。
【问题讨论】:
标签: javascript php cors