I have a PHP function that returns a value or a blank page and I want to check it with JS.
PHP:
function get_CTDIvolAVG($min, $max) {
$query = "SELECT AVG(ct.ctdivol_mGy) FROM exam
INNER JOIN ct on exam.examID = ct.examID AND ct.ctdivol_mGy > 0
WHERE exam.modality = 'CT'
AND (unix_timestamp(exam.date)*1000) >= '" . $min . "'
AND (unix_timestamp(exam.date) * 1000) < '" . $max ."';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
echo $line["AVG(ct.ctdivol_mGy)"];
}
JS:
function afterSetExtremes(e) {
var chart = $('#container').highcharts();
$.getJSON('http://localhost/public_html/webservice.php/CT/CTDIvol/AVG/' + Math.round(e.min) +
'/' + Math.round(e.max), function (AVG) {
if (AVG) {
chart.yAxis[0].removePlotLine('avg');
chart.yAxis[0].addPlotLine({
value: AVG,
color: 'green',
width: 2,
id: 'avg',
dashStyle: 'longdashdot',
label: {
text: 'CT Average: ' + AVG.toFixed(2)}
});
} else {
console.log('blank');
}
});
}
When PHP code returns nothing, it should enter the else clause in JS and print 'blank' but it doesn't happen.
How can I fix this?
console.log(AVG)what do you get