Hello,
I always get the CORS error when getting data from a php file using GET (ajax jquery), the php file and js file is stored locally. Does anyone have the same issue? On another php file it works with the same script just with another POST…
Name: epiz_31877454
Error Message:
Access to XMLHttpRequest at ‘https ://errors.infinityfree.net/403/’ (redirected from 'MYLINK) from origin ‘MY DOMAIN’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
GET https:// errors.infinityfree.net/403/ net::ERR_FAILED
send @ jquery-3.6.0.js:10109
ajax @ jquery-3.6.0.js:9690
retrieveData @ obrd-script.js:8
(anonym) @ index.php?page=leaderboard:29
errors.infinityfree.net/:1
GET https:|/ /errors.infinityfree.net/errors/404/ 404
js:
$.ajax({
url: 'includes/functions/getLeaderboardData.php',
type: 'GET',
async: true,
data: {getLeaderboard : 'true'},
success: function (data) {
output += data
}
});
php:
session_start();
include_once('../../includes/functions/db_credentials.php');
include_once('../../includes/functions/db_connection.php');
if(isset($_GET["getLeaderboard"]))
{
$SQL = "SELECT idUsername, dtCredits FROM tbluser ORDER BY dtCredits DESC";
$result = mysqli_query($dbc, $SQL);
if(mysqli_errno($dbc))
{
die("wrong SQL: $SQL Error: " . mysqli_error($dbc));
}
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
$row = mysqli_fetch_assoc($result);
echo"<tr>
<td>{$row["idUsername"]}</td>
<td>{$row["dtCredits"]}</td>
</tr>";
}
}