I am working with a map and data. When you click on a state, it pulls the appropriate data from the JSON and displays the stores in an unordered list. If a state does not have data (Wyoming is one for example), it should be logging to the console that it is empty. So when you click on Wyoming, it should realize the array is empty and log that its empty to the console.
$("#paginateView").hide();
$("#stateButton").hide();
$("#mapWhereToBuy").usmap({
click: function(event, data) {
$.ajax({
url: 'https://165.227.69.79:8443/alanric/armaster/state/' + data.name + '?callback=functionCall',
dataType: "jsonp",
cache: true,
jsonpCallback: "functionCall",
success: function(json){
console.log(json);
var storeNames = '<ul class="list-group">';
$.each(json, function (i, item) {
var stores = item.cname;
if (stores && stores.length) {
storeNames += '<li class="content list-group-item">' + stores + '</li>';
} else {
console.log("Sorry, we do not carry products in your state.");
}
});
storeNames +='</ul>';
$('#clicked-state').html(storeNames);
$("#paginateView").show();
$("#stateButton").show();
$("#stateButton").html('You Selected:' + ' ' + data.name);
pageSize = 15;
showPage = function(page) {
$(".content").hide();
$(".content").each(function(n) {
if (n >= pageSize * (page - 1) && n < pageSize * page)
$(this).show();
});
}
showPage(1);
$("#paginateView li a").click(function() {
$("#paginateView li a").removeClass("current");
$(this).addClass("current");
showPage(parseInt($(this).text()))
});
}
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.cento.com/js/raphael.js"></script>
<script src="https://www.cento.com/js/jquery.usmap.js"></script>
<div id="mapWhereToBuy"></div>
<h1>Search By State</h1>
<h4>Click on a state to see store locations</h4>
<hr>
<div id="clicked-state"></div>