[英]Ionic Laravel API PUT issue
我正在努力满足以下要求:
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错误。 提前致谢!
如果您使用Google Access-Control-Allow-Origin ,则第一个匹配项是https://developer.mozilla.org/en/docs/HTTP/Access_control_CORS
您需要在您的nginx或apache2配置中允许ajax调用。
使用谷歌为他们两个找到好的配置。 例如,nginx:
add_header 'Access-Control-Allow-Origin' '*';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.