Created
August 21, 2024 19:32
-
-
Save saaiful/c1f31e43834e8f94fe38d688caa106b5 to your computer and use it in GitHub Desktop.
latest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadLatestContent() { | |
// Define the target element where the content will be rendered | |
const $targetElement = $('.desktopSectionListMedia.listItemLastBB0'); | |
// Fetch the latest content from the server | |
$.ajax({ | |
url: '/ajax/latest', | |
method: 'GET', | |
dataType: 'json', // Expecting a JSON response | |
success: function(data) { | |
// Clear any existing content | |
$targetElement.empty(); | |
// Iterate over the fetched data and construct the HTML for each item | |
$.each(data, function(index, item) { | |
const $mediaDiv = $('<div>', { class: 'media positionRelative paddingLR10' }); | |
$mediaDiv.html(` | |
<div class="media-left paddingR5"> | |
<div class="positionRelative"> | |
<img class="media-object borderRadius5" src="${item.image}" width="100" alt="${item.alt}"> | |
</div> | |
</div> | |
<div class="media-body"> | |
<h4 class="margin0 marginL5 hoverBlue title12">${item.title}</h4> | |
</div> | |
<a aria-label="${item.title}" href="${item.link}" class="linkOverlay"></a> | |
`); | |
// Append the constructed HTML to the target element | |
$targetElement.append($mediaDiv); | |
}); | |
}, | |
error: function(xhr, status, error) { | |
console.error('Error fetching latest content:', error); | |
} | |
}); | |
} | |
// Call the function to load and render the content | |
loadLatestContent(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment