I don't have control over the returned XML feed, so i was wondering how I could limit the amount of items returned.
I need help structuring the for loop, assuming that's the best approach for my goal.
Currently, my code looks like this:
HTML:
<div id="results"></div>
AJAX Get request to PHP file to convert XML to string:
$.get('mydomainhere/feed.php', {}, showPosts);
function showPosts(data){
var posts = $(data).find('channel>item');
var str = "<ul>";
$.each(posts,function(index,value){
var title = $(value).find('title').text();
var description = $(value).find('description').text();
str+= "<li>";
str+= "<div>";
str+= "<h3>" + title + "</h3>";
str+= "<p>" + description + "</p>";
str+= "</div>";
str+= "</li>";
});
str+= "</ul>";
$('#results').html(str);
};
The PHP feed file:
<?php $feedData = file_get_contents('xml-test.xml'); echo $feedData; ?>