Php 当ajax结果返回空值时显示错误消息

Php 当ajax结果返回空值时显示错误消息,php,sql,ajax,error-messages-for,Php,Sql,Ajax,Error Messages For,我想问一下,当SQL生成ajax中的null值和0值时,如何显示错误消息 {"value": {"columns": [["More than 85%",null],["Less than 85%",0]], "type":"pie"} } 否则不会显示弹出消息 $.ajax({ type: "POST", url: "charts/prod.php?year=" + $("#selectyear").val() + "&month=" + $("#se

我想问一下,当SQL生成ajax中的null值和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');
        }
    }   
});
试试这个

$.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'); 
   }   
 });

变量
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');
    }   
});

您确定PHP脚本在没有可用数据时返回
json\u encode(null)
json\u encode(0)
吗?也许您应该测试
if(result.value==null)
而不是
if(result==null)
?{value:{“columns:[“大于85%”,null],“小于85%”,0]],“type”:“pie”}结果为空,0这是
result.value.columns[0][1]==null
result.value.columns[1][1]==0
{“百分比”:[“-100”,“0”,“0”,“-50”,“-50”,“0”,“0”,“新”:“0”,“待定”:“0”,“已完成”:“1”,“正在进行”:“1”,“延迟”:“1”}您能在这里发布您的回复吗??我只是想看看服务器发送了什么响应,并据此提出建议。