I implemented an ajax function that retrieves three images (PORTRAIT, SQUARE, and LANDSCAPE) from a JSON response:
$.ajax({
url: link,
method: 'GET',
headers: {
"Authorization": authToken
},
}).then(function (response) {
var data = response;
$("#imageid").css("border-color", "#ccc");
$(".search-results").empty();
for (var prop in data.entity.entries) {
if (data.entity.entries.hasOwnProperty(prop)) {
var imgURL = data.entity.entries[prop].uri + "&" + imageCacheBust;
$(".search-results").append($("<li><a href='" + imgURL + "' target='_blank'><div class='thumbnail'><img width='30' height='30' src='" + imgURL + "' target='_blank'/></img><div class='caption'><p>" + data.entity.entries[prop].orientation + "</p></div></a></li>"));
}
}
}).fail(function (errorData) {
$(".search-results").empty();
$(".search-results").append("<p class='alert alert-danger'>Invalid ID</p>");
$("#imageid").css("border-color", "red");
});
The LANDSCAPE and SQUARE images come back as URIs structured like this:
http://xx.domain.com/api/v2/img/55527b6060b27c50d1def7b6?location=LANDSCAPE&1
http://xx.domain.com/api/v2/img/55527b6060b27c50d1def7b6?location=SQUARE&1
However, the PORTRAIT image URI appears as:
http://xx.domain.com/api/v2/img/5550fdfe60b27c50d1def72d&43
I attempted to use a regex pattern to remove everything following the LAST occurrence of d
at the end of the portrait URL to avoid caching issues. Unfortunately, this manipulation is not functioning correctly, resulting in the image failing to display.