I've got a game which refreshes info every 10 seconds from a MySQL database. There will be a JS function which is called each time this happens. I can't get the success function to execute, and I have no idea why. No errors on the console, either.
Javascript:
function refreshStats() {
console.log("number 1");
$.ajax({
url: "refreshData.php",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType : 'json',
data: { },
cache: false,
async: true,
success: function (msg) {
if(msg){
console.log("number 2");
var arr = JSON.parse(msg);
document.getElementById("interface_stats").innerHTML =
"Fatigue: " + arr[0];
}
}
});
}
PHP:
<?php
$username = $_POST['user'];
ini_set('display_errors', 1);
error_reporting(E_ALL);
$con = mysql_connect("localhost","redacted","redacted");
if (!$con)
{
die('SQL error! Aborting: ' . mysql_error($con));
}
$db = mysql_select_db("aftertheend",$con) or die("Database error! Aborting. Inform the admin.");
$query = "SELECT fatigue, food, water, radiation, condition FROM users WHERE username='TheMightyThor'";
$result = mysql_query($query, $con);
$data = mysql_fetch_row($result);
$stats = [
"fatigue" => $data[0],
"food" => $data[1],
"water" => $data[2],
"radiation" => $data[3],
"condition" => $data[4]
];
echo json_encode($stats);
?>