I would like to ask how to display error message when null value and 0 value in the ajax result from SQL
{"value":
{"columns": [["More than 85%",null],["Less than 85%",0]],
"type":"pie"}
}
else no pop out message shown.
$.ajax({
type: "POST",
url: "charts/prod.php?year=" + $("#selectyear").val() + "&month=" + $("#selectmonth").val(),
dataType: "json",
success: function (result) {
var chart = c3.generate({
bindto: '#piepie',
data: result.value,
color: {
pattern: ['#f35213', '#f1af4c']
},
pie: { title: "Productivity", }
});
},
error: function() {
if ((result == null) && (result == 0)){
alert ('Data are not ready yet!!');
}
else {
('error');
}
}
});
The variable
result
doesn't exist in theerror:
function. You need to do that test in thesuccess:
function.The
null
and0
values are deep in the structure, you need to access them properly.