What I'm trying to do is query a variable in my check.php file and pull that variable to my index.php file, compare it to a different variable, and reload the page if they don't match. This is what I have so far:
check.php:
some query
echo json_encode($checknew);
index.php:
var checkold = "<?php echo $old['ertek'];?>";
function checkupdates() {
setInterval(function() {
$.ajax({
type: 'POST',
url: 'check.php',
dataType: 'json'});
if (checkold != checknew){
location.reload();
}
, 3000)}
};
$( document ).ready( checkupdates );
How do I "catch" the $checknew variable from php and turn it into a variable for my function?
ajaxcall correctly. Need to use.done(function() {}to get the echo value from check.phpvar checkold = "<?php echo $old['ertek'];?>";is not doing what you think it is.checkoldwill contain the literal string<?php echo $old['ertek'];?>not the value inside$old['ertek']. Please check out Ajax Documentation