【发布时间】:2014-04-11 16:20:46
【问题描述】:
我正在努力处理以下请求:
var spice = $http.put("http://localhost:8000/api/v1/Spices/", sanitizeSpice(spice, id));
sanitizeSpice 返回类似 {amount: "54", id: "2")的东西
我收到以下错误:
XMLHttpRequest cannot load http://localhost:8000/api/v1/Spices/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
我在 Laravel 中设置了以下过滤器(如我在此处找到的其他示例所示):
App::before(function($request)
{
if (Request::getMethod() == "OPTIONS") {
$headers = array(
'Access-Control-Allow-Origin', 'http://localhost',
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers'=> 'X-Requested-With, content-type',);
return Response::make('', 200, $headers);
}
});
App::after(function($request, $response)
{
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'POST,GET,DELETE,PUT,OPTIONS');
});
我做错了什么?我没有收到关于 POST、GET 或 DELETE 的错误。提前致谢!
【问题讨论】:
标签: angularjs laravel xmlhttprequest