我正在努力满足以下要求:
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的错误。提前感谢!
发布于 2014-04-11 08:20:46
如果你在谷歌上搜索Access-Control-Allow-Origin,,第一个成功的是CORS
您需要在nginx或apache2配置中允许ajax调用。
使用谷歌为两者找到好的配置。例如nginx:
add_header 'Access-Control-Allow-Origin' '*';https://stackoverflow.com/questions/23002486
复制相似问题