タイトルの通り、Jqueryでajaxを使用し、他サイトの情報を所得したいが所得できずに困っています。
html
1<head> 2<script> 3$(function(){ 4 $('.sample_btn').click(function(){ 5 $.ajax({ 6 url: 'https://kinocolog.com/ajax/test.html', 7 type: 'GET', 8 dataType: 'html' 9 }).done(function(data){ 10 $('.result').html(data); 11 }).fail(function(data){ 12 alert('通信失敗!'); 13 }); 14 }); 15}); 16</script> 17</head> 18<body> 19 <div class="result">ここにajaxの結果を書き換えます</div> 20<input type="button" class="sample_btn" value="ajax通信で取得する"> 21</body> 22</html>
urlのサイトから所得したhtmlデータを.resultに表示したいのですが失敗してしまいます。
Consoleには以下記載がありました。
Access to XMLHttpRequest at 'https://kinocolog.com/ajax/test.html' from origin 'http://127.0.0.1:8887' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Cross-Origin Read Blocking (CORB) blocked cross-origin response https://kinocolog.com/ajax/test.html with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
クロスドメインによるエラーなのかと思い、自分なりに調べましたが解決法が分からず質問させていただきます。上記に載っているサイトだけでなく、どんなサイトからも情報が所得できるような解決法があれば是非お教え願いたいです。ご教授よろしくお願いします。
回答4件
あなたの回答
tips
プレビュー