相关疑难解决方法(0)

Slim Framework - jQuery $ .ajax请求 - Access-Control-Allow-Methods不允许使用方法DELETE

我正在尝试使用Slim Framework编写的REST API.

Get&Post方法没有任何问题.但是DELETE请求不起作用.我得到" Access-Control-Allow-Methods " 不允许 " 方法删除 "

我已经允许OPTIONS以及标题中的DELETE.见下面的代码.

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');

$app->options('/(:name+)', function() use($app) {                  
    $response = $app->response();
    $app->response()->status(200);
    $response->header('Access-Control-Allow-Origin', '*'); 
    $response->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, X-authentication, X-client');
    $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
 });
Run Code Online (Sandbox Code Playgroud)

这个请求失败的原因是什么?

ajax rest slim http-delete

6
推荐指数
1
解决办法
7907
查看次数

标签 统计

ajax ×1

http-delete ×1

rest ×1

slim ×1