【发布时间】:2013-07-17 14:15:20
【问题描述】:
我正在通过 jQuery 的 $.ajax 进行跨域请求以访问 RESTful PHP API。
为此,我在 PHP 中设置了以下标头:
header("HTTP/1.1 $code $status");
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT');
使用GET 和POST 类型没有问题。但是,当我执行 PUT ajax 调用时,Firefox 完全失败并在 Firebug 的网络选项卡中显示 OPTIONS api.php。
在 Chrome 中,同样的事情首先发生(OPTION 请求失败并显示消息 Method PUT is not allowed by Access-Control-Allow-Methods.)但 Chrome 会跟进实际的 PUT 请求
那实际上是有效的。
这种行为的原因是什么?
【问题讨论】:
标签: jquery ajax cross-domain put