I can't figure out why this isn't working! The idea is the code is supposed to run a php script on another page that will check for changes in the DB state. Then it will return a string that will update the CURRENT page.
(External) PHP:
$QgetShift = mysql_query("SELECT * FROM shifts");
$num = mysql_num_rows($QgetShift);
if(isset($_POST['ajax'])) {
if(isset($_SESSION['data'])) {
$data = $_SESSION['data'];
if($data != $num){
$_SESSION['data'] = $num;
echo "WORKING";
} else {
echo "NOT WORKING";
}
} else {
$_SESSION['data'] = $num;
echo "started";
}
}
HTML:
<button type="button" id="clickMe">Click Here</button> <br />
<div id="data"></div>
Javascript:
$('#clickMe').click(function(){
$.ajax({
method: 'post',
url: 'function.php',
data: {
'ajax': true
},
success: function(data) {
$('#data').text(data);
}
});
});
Can anyone tell me if there is an error somewhere?