function OnTestGet() {
console.log("OnGet Button Click JavaScript!!");
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.google.com/");
xhr.send();
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
const data = xhr.response;
console.log(data);
} else {
console.log(`Error: ${xhr.status}`);
}
};
}
OnTestGet();
外部にリクエストするために上記のようなコードを埋め込んで実行すると以下のようなCORS policyに関するエラーが表示されます。回避する方法を教えてください。
Access to XMLHttpRequest at ‘https://www.google.com/’ from origin ‘https://xxxxxxxxxxxx.myshopify.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.