【发布时间】:2021-11-02 19:54:37
【问题描述】:
我正在尝试向 musicbrainz api 发出 ajax 请求,但不断收到 cors 标头错误。
错误:Access to XMLHttpRequest at 'https://musicbrainz.org/ws/2/release-group/?xxxxxxx' from origin 'https://my_url' has been blocked by CORS policy: Request header field x-csrf-token is not allowed by Access-Control-Allow-Headers in preflight response.
代码
var $artist_encoded = encodeURIComponent($artist);
var $album_encoded = encodeURIComponent($album);
$.ajax({
type: "GET",
url: "https://musicbrainz.org/ws/2/release-group/?query=artist:%22" + $artist_encoded + "%22%20AND%20releasegroup:%22" + $album_encoded + "%22",
dataType: "xml",
success: myfunction
});
【问题讨论】:
标签: javascript jquery laravel csrf