I am trying to execute a php file from a javascript function with AJAX/JQuery - nothing I have found so far works. The file with the javascript is index.php and getTemps.php is in the same directory on my apache server. I have found that getTemps works fine so it must be how I'm calling it from index.php.
getTemps.php: reads last line of file that updates every minute
<?php
$lastLine = shell_exec('tail -1 temps.log');
$temps = explode(" ", $lastLine);
echo $temps;
?>
javascript from index.php: this code is inside a function which gets called every minute
var tempString;
$.get("getTemps.php", function(data) {
tempString = data;
});
I have also tried these with no luck.
$.ajax({url: 'getTemps.php', success: function(data) { tempString = data; }});
$.ajax({
url : 'getTemps.php',
type : 'GET',
data : data,
dataType : 'string',
success : function (data) {
tempString = data
}
});
Any help would be awesome. Been stuck on this for awhile. Thanks in advance!