Bac*_*ice 33 javascript ajax jquery json
$.getJSON(url, function(json) {
var output = '';
$.each(json, function(i,d) {
if(d.DESCRIPTION == 'null'){
console.log("Its empty");
}
var description = d.DESCRIPTION;
output += '<tr><td>'+d.NAME+'</td><td>'+'<tr><td>'+d.DESCRIPTION+'</td><td>';
});
});
Run Code Online (Sandbox Code Playgroud)
我试过添加
if(d.DESCRIPTION == 'null'){ console.log("Its empty");
Run Code Online (Sandbox Code Playgroud)
检查返回的对象是否为空,但不起作用.
有人可以向我解释这有什么问题吗?
Aru*_*ngh 67
下面的代码(jQuery.isEmptyObject(anyObject)函数已经提供)工作完全正常,无需编写自己的一个.
// works for any Object Including JSON(key value pair) or Array.
// var arr = [];
// var jsonObj = {};
if (jQuery.isEmptyObject(anyObjectIncludingJSON))
{
console.log("Empty Object");
}
Run Code Online (Sandbox Code Playgroud)
use*_*654 56
只测试数组是否为空.
$.getJSON(url,function(json){
if ( json.length == 0 ) {
console.log("NO DATA!")
}
});
Run Code Online (Sandbox Code Playgroud)
if (!json[0]) alert("JSON empty");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134120 次 |
| 最近记录: |