jQueryでローカルのファイルを読み込もうとしたらエラー「Access to XMLHttpRequest at ‘file:///ファイルパス’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.」 | クズリーマンのカス備忘録

jQueryでローカルのファイルを読み込もうとしたらエラー「Access to XMLHttpRequest at ‘file:///ファイルパス’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.」

jQueryのロゴ jQuery
スポンサーリンク

事象

jQueryでローカルのファイルを読み込もうとしたら読み込めてない模様。

chromeのコンソールで確認すると、以下のエラーが出てた。

「Access to XMLHttpRequest at ‘file:///ファイルパス’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.」

 

原因

ローカルのファイルは読み込めぬ模様。

 

対応

以下いずれか。

  • ブラウザのセキュリティを下げた状態で起動する
    • > Chrome なら –allow-file-access-from-files オプションを付けてブラウザを起動してください。(出典)
  • サーバ立ててから、そのサーバ上で実行する

 

コメント

タイトルとURLをコピーしました