I have a little script which grabs some JSON content for a webshop menu. Sometimes a category doesn't have products in it so when the array is empty a "no products found" line must be showed. I tried this with jQuery.isEmptyObject() but now the text is only showed at categories WITH products in it. The menu itself works perfectly except for the thing above...
So my question: How can I check if json.products or product is empty? If so how would you incorporate that and the end of the script?
Probably an easy one for you.... I don't see it anymore ;)
What I have:
function widget(catId, catHref){
var url = catHref + 'page1.ajax?limit=4';
$.getJSON(url, function (json){
var productsHtml = [];
$.each(json.products, function(index, product){
var productHtml = '' +
..... blablabla .....
productsHtml.push(productHtml);
});
productsHtml = productsHtml.join('');
if (jQuery.isEmptyObject(json[productsHtml])) {
$('#widget-products'+catId+' ul').html('No products');
} else{
$('#widget-products'+catId+' ul').html(productsHtml);
}
});
}