Reputation: 539
How would I go about writing conditionals for the below ajax that says if one of these fields returns empty don't return part of the string? Any help would be MOST appreciated:
$.ajax({
url: "http://www.lcbcchurch.com/mobileJSON/events",
dataType: "json",
success: function (data) {
eventResults(data);
}
});
function eventResults(data) {
for (var i = 0; i < data.length; i++) {
// this will log all of the images url
console.log(data[i]["event-image"]);
// just access the part you want by it's name.
$("#event-images").append("<a href='#" + data[i]["url_title"] + "' id='event-button' data-role='button'><img class='pics' src='" + data[i]["event-image"] + "' width='" + 156 + "' height='" + 74 + "'></a>");
$(".wrapper").prepend("<div id='" + data[i]["url_title"] + "' class='event-detail' data-role='page'><div class='back-header' data-role='header'><a href='events.html' data-icon='delete' iconpos='notext'>Cancel</a><h1></h1><a href='" + data[i]["event-registration"] + "' data-icon='arrow-r' data-iconpos='right' data-theme='b'>Register</a></div><img src='" + data[i]["event-image"] + "' /><strong>DATE: " + data[i]["event-date"] + "</strong><strong>LOCATION: " + data[i]["event-location"] + "</strong><strong>DEADLINE: " + data[i]["event-deadline"] + "</strong>" + data[i]["event-description"] + "</div>");
$("#event-slider").append("<a href='" + data[i]["event-image"] + "'></a>");
}
$('.loading-wrapper').empty();
// Call the pics ready function
eventPics();
}
Upvotes: 0
Views: 129
Reputation: 2619
Something like this I think. Don't have time to test.
if (data[i]["url_title"] != undefined) {
$("#event-images").append("<a href='#"+data[i]["url_title"]+"' id='event-button' data-role='button'><img class='pics' src='"+data[i]["event-image"]+"' width='"+156+"' height='"+74+"'></a>");
}
Upvotes: 1