Last active
April 26, 2025 23:56
-
-
Save juanbrujo/3a71489572e5677fcec7e14676aa66e2 to your computer and use it in GitHub Desktop.
Get and display last feed from RSS using JavaScript (jQuery)
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
<html> | |
<head></head> | |
<body> | |
<div class="noticia">CARGANDO</div> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<script> | |
$(function(){ | |
var url = 'https://www.domain.co/index.xml'; | |
var news = $('.noticia'); | |
function dateFormat(pubDate) { | |
var date = new Date(pubDate); | |
var months = Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); | |
return date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear() | |
} | |
function loadNews(url) { | |
$.ajax({ | |
url: url, | |
type: 'GET', | |
dataType: "xml" | |
}) | |
.done(function(xml) { | |
var self = $(xml).find('channel item').first(); | |
var url = $(self).find('link').text(); | |
var title = $(self).find('title').text(); | |
var text = $(self).find('description').text(); | |
var date = $(self).find('pubDate').text(); | |
news.html('<h2>' + title + '</h2><p>' + dateFormat(date) + '</p><p>' + text + '</p><a href="' + url + '">Link</a>'); | |
}) | |
.fail(function(){ | |
news.hide(); | |
}); | |
} | |
loadNews(url); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, thanks to your article I have consulted and completed my page.
a small world cup