4.

Access to XMLHttpRequest at 'url1' from origin 'url2' has been blocked by CORS policy

編集

エラー内容

Access to XMLHttpRequest at 'url1' from origin 'url2' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

発生条件/原因/対処法

とあるサイトからajax等を利用して異なるドメインのリソースにアクセスした際に発生するエラー。

対策としてはajaxで投げるurlを自サイトにしてサーバーサイドで異なるドメインのapiにアクセスしてその結果をリターンさせればよい。(クライアント的には自サイトにしかアクセスしていないことになる)

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. Uncaught TypeError: Illegal invocation
  2. Form submission canceled because the form is not connected
  3. Uncaught TypeError: location.href is not a function
  4. Access to XMLHttpRequest at 'url1' from origin 'url2' has been blocked by CORS policy
  5. Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')