Created
February 2, 2011 10:14
-
-
Save metamn/807504 to your computer and use it in GitHub Desktop.
Reading a (Shopify) feed with 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
<div id="blog"> | |
{% assign feed_url = "http://shopledge.myshopify.com/blogs/news.atom" %} | |
<script type="text/javascript"> | |
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q={{ feed_url }}&num=5"; | |
jQuery.getJSON(api, function(data){ | |
// Check for error | |
if (data.responseStatus == 200) { | |
// Process the feeds | |
var feed = data.responseData.feed; | |
var msg = feed.title; | |
msg += '<ul>'; | |
for (var i=0; i<feed.entries.length; i++) { | |
var entry = feed.entries[i]; | |
var entryDate = new Date(entry.publishedDate); | |
var pubDate = entryDate.toLocaleDateString(); | |
msg += '<li><a href="'+ entry.link +'" title="View this feed at '+ feed.title +'">'+ pubDate + entry.title +'</a>'; | |
msg += '<div>'+ entry.content + '</div></li>'; | |
} | |
msg += '</ul>'; | |
} else { | |
// Handle error if required | |
if (options.showerror) | |
if (options.errormsg != '') { | |
var msg = options.errormsg; | |
} else { | |
var msg = data.responseDetails; | |
}; | |
}; | |
jQuery("#feed").append(msg); | |
}); | |
</script> | |
<div id="feed"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment