I recently attempted to set up Ajax calls and stumbled upon the following code snippet:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Let AJAX update this text.</p>
<button type="button" onclick="loadDoc()">Update Content</button>
<script>
function loadDoc() {
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
}
xhttp.open("GET", "www.google.com", true);
xhttp.send();
}
</script>
</body>
</html>
As I tried to access the URL, an error message stating "XHR cannot load" appeared. I understand that it has something to do with CORS. Despite consulting various resources, I am struggling to comprehend the issue. Can someone please clarify and help resolve this matter? Any assistance would be greatly appreciated.