我想问一下如何在SQL中的ajax结果中显示空值和0值时显示错误消息
{"value":
{"columns": [["More than 85%",null],["Less than 85%",0]],
"type":"pie"}
}
否则显示没有弹出消息。
$.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');
}
}
});
答案 0 :(得分:1)
result
函数中不存在变量error:
。您需要在success:
函数中进行该测试。
null
和0
值在结构深处,您需要正确访问它们。
$.ajax({
type: "POST",
url: "charts/prod.php?year=" + $("#selectyear").val() + "&month=" + $("#selectmonth").val(),
dataType: "json",
success: function (result) {
if (result.value.columns[0][1] == null && result.value.columns[1][1] == 0) {
alert ('Data are not ready yet!!');
} else {
var chart = c3.generate({
bindto: '#piepie',
data: result.value,
color: {
pattern: ['#f35213', '#f1af4c']
},
pie: { title: "Productivity", }
});
}
},
error: function() {
alert('error');
}
});
答案 1 :(得分:0)
试试这个,
$.ajax({
type: "POST",
url: "charts/prod.php?year=" + $("#selectyear").val() + "&month=" + $("#selectmonth").val(),
dataType: "json",
success: function (result) {
if ((result == null) && (result == 0)){
alert ('Data are not ready yet!!');
}else {
var chart = c3.generate({
bindto: '#piepie',
data: result.value,
color: {
pattern: ['#f35213', '#f1af4c'] },
pie: { title: "Productivity", }
});
}
},
error: function() {
alert('error');
}
});