【发布时间】:2018-01-11 00:46:19
【问题描述】:
我正在尝试从 localhost 访问 Deezer API,但我不断收到以下错误:
Fetch API cannot load http://api.deezer.com/search/track/autocomplete?limit=1&q=eminem.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
localhost 的响应标头确实有 Access-Control-Allow-Origin 标头 (访问控制允许来源:*)。
我正在使用 fetch,例如:
fetch('http://api.deezer.com/search/track/autocomplete?limit=1&q=eminem').
我做错了什么?
【问题讨论】:
-
api 是否使用
access-control-allow-origin: *响应该请求?还是这个演员 localhost 中的access-control-allow-origin:<your origin>? -
不使用 cors definitin 将有助于一些标题不需要的 api
标签: javascript cors localhost fetch-api deezer