Reputation: 960
So, I was trying to merge two feeds, and display it in two columns sorting by time, starting as the newest from the top left corner, and the oldest at the bottom right corner. To be precise, this is the order that I want:
------------------------
Newest | 4th Newest
2nd Newest | 5th Newest
3rd Newest | 6th Newest
------------------------
The problem is, the following code did not work, and returned an error
Uncaught TypeError: item is not a function (index:329)
The code I used is below.
<script>
$(document).ready(function() {
var blogFeed = $.ajax({
type: "GET",
url: "http://www.foxinflame.tk/blog/feed",
dataType: "xml"
})
var videoFeed = $.ajax({
type: "GET",
url: "/videoFeed.php",
dataType: "xml"
})
$.when(blogFeed, videoFeed).done(function(blogXML, videoXML){
//The one below this one is the 329 line
var combinedXML = $(blogXML).find("item").concat(videoXML.find("entry"));
var sortedXML = combinedXML.sort(function(videoFeedCompare, blogFeedCompare){
var videoFeedDate = Date.parse(videoFeedCompare.find("published"));
var blogFeedDate = Date.parse(blogFeedCompare.find("pubDate"));
return videoFeedDate - blogFeedDate;
});
console.log(sortedXML.item(0));
sortedXML.forEach(function(eachCounter) {
console.log("stuff");
var title = $(this).find("title").text();
console.log(title);
var description = $(this).find("description").text();
var comments = +($(this).find("slash:comments").text());
var pubDate = $(this).find("pubDate").text();
var link = $(this).find("link").text();
if(eachCounter < 3){
$("#firstColumnOfItems").append("<div class='postCollection'><div class='z-depth-1 blogpost' style='min-height: 300px'><br><h5><a style='color:black' href='"+link+"'>"+title+"</a></h5><br><p>"+description+"<br><i>"+comments+" Comments. Published at "+pubDate+"</i></p></div></div>");
} else if(eachCounter < 6) {
$("#secondColumnOfItems").append("<div class='postCollection'><div class='z-depth-1 blogpost' style='min-height: 300px'><br><h5><a style='color:black' href='"+link+"'>"+title+"</a></h5><p>"+description+"<br><i>"+comments+" Comments. Published at "+pubDate+"</i></p></div></div>");
}
});
});
})
</script>
Do note, that VideoFeed.php just does file_get_contents
and echos it, because JS couldn't do it (no access control allow origin header is present).
What is wrong, and How would I fix it?
Upvotes: 2
Views: 100
Reputation: 696
Change console.log(sortedXML.item(0));
to console.log(sortedXML.item[0]);
Upvotes: 1