I have been researching this problem for like 2 days with no solution on sight. Also I have no idea why this had to be so difficult. I am trying to catch data from another site, to localhost. It is not allowing me whatever I try to do. I searched for 2 days, modified apache header to header('Access-Control-Allow-Origin: *'); In PHP. Also in .htaccess. I researched other answers, on stack and other sites with absolutely no change.
Here is my default.js file:
$.ajax({
type: "GET",
url: "http://anothergames.com",
dataType: 'json',
cache: false,
success: function(data)
{
console.log('hello world!');
}
});
Here is index.php:
<?php
header('Access-Control-Allow-Origin: *');
echo '<!doctype html>
<html>
<head>
<title>Marrja e te dhenave per udhetimet turistike nga website nepermjet Ajax</title>
<link rel = "stylesheet" href = "default.css">
<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
</head>
<body>
Hello World!
<script src = "js/jquery.min.js"></script>
<script src = "js/default.js"></script>
</body>
</html>';
Also changed localhost to something else. Still nothing. Tried other solutions, but new problems arise, with mime type mismatch and forced mime type.
If you have any idea, let me know. Am using xampp in windows 10 and Chrome. This is the error I get.