我正在尝试接受成功函数中的json,即数据,我将数据作为[],但我没有在警告框中获得无数据。有什么我想念的,任何人都可以提供帮助。提前致谢
success: function (data) {
$('#loader').hide();
if (data != null) {
alert('congratulations');
}else{
alert('no data');
}
}
答案 0 :(得分:1)
尝试用if (data != null)
if ((data || []).length)
答案 1 :(得分:0)
如果您希望将数据作为数组,那么要测试它是否为空,请检查其长度:
if (data && data.length > 0) {
// ...
}
因为空数组[]
不是null
。
答案 2 :(得分:0)
写入条件时,这些值被视为false:'',0,[],undefined,null
success: function (data) {
$('#loader').hide();
if (data == true)
alert('congratulations');
else
alert('no data');
}