我正在通过 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工作没有问题。但是,当我进行PUTajax 调用时,Firefox 完全失败并显示OPTIONS api.php在 Firebug 的网络选项卡中。
在 Chrome 中,同样的事情首先发生(OPTION请求失败并显示消息Method PUT is not allowed by Access-Control-Allow-Methods.),但 Chrome 会跟进PUT实际工作的实际请求。
这种行为的原因是什么?