Very basically, I'm trying to set the value of a variable in one file based on the return value of a function in another file. This is then returned via AJAX, however, the AJAX always seems to indicate an error. Code below:
updateTurn.php
<?php
//This is called by AJAX
require_once('functions.php'); //include necessary file
$player = getCurrentTurn(); //call function
echo $player;
?>
functions.php
...
function getCurrentTurn()
{
//the query and connection function appropriately
include_once("getConn.php");
$query = $GLOBALS['conn']->prepare("SELECT turn FROM Game");
$query->execute();
$result=$query->fetch(PDO::FETCH_ASSOC);
return $result['turn']; //return the result of the query
}
...
AJAX
function checkForTurnChange(){
$.ajax({
type:"GET",
url:"updateTurn.php",
async:true,
cache:false,
timeout:10000,
success:function(data){
alert(data);
},
//this is where AJAX is returning
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(textStatus +": "+ errorThrown);
}
});//end AJAX
};//end function
The error is caused by the line $player = getCurrentTurn();. If I remove this and echo any string value then it works correctly. This is incredibly basic but I can't seem to see my error. All help appreciated.
EDIT: The AJAX calls error: which results in this alert :

getCurrentTurn()contained in a class in functions.php file?errorcallback is being fired that points to anhttperror