I am facing an issue with accessing elements of an HTML page through JavaScript. I have tried different methods, but I keep getting the error message:
CORS header "Access-Control-Allow-Origin" missing
. Here is the code snippet I tried:
<!DOCTYPE html>
<html lang="en>
<head>
<meta charset="utf-8" />
<title>WEBSITE</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$.ajax("https://www2.casailaria.it/news/", {
dataType: "jsonp",
cors: true,
secure: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
success: function (response) {
console.log(response);
}
});
</script>
</body>
</html>
I am determined to find a solution and would appreciate any advice on what adjustments I need to make for it to work correctly. Any suggestions on JavaScript solutions or ajax calls from a CDN are welcomed. Thank you in advance!