Reputation: 1202
I'm trying to grab a rss feed and display the contents on a mobile device via apache cordova. However, if I don't supply the url that points to a .xml file, the reader does not load. For example,
var feedUrl = "https://newsline.com/feed/";
this does not load, but if I use
var feedUrl = "http://feeds.bbci.co.uk/news/technology/rss.xml";
it works. Here is the rss reader javascript file I am using:
/**
* Fetch RSS and display the contents of it
*/
Feed.prototype.load = function() {
var self = this;
$(this.maskEl).show();
$(this.errorEl).text('');
$.ajax({
url: this.url,
dataType: 'text',
crossDomain: true,
success: function(data) {
data = $.parseXML(data.trim());
$(self.listEl).empty();
// Display RSS contents
var $rss = $(data);
$rss.find('item').each(function() {
var item = this;
$(self.listEl).append(self.createListElement(item));
});
},
error: function() {
$(self.errorEl).text('Failed to load RSS.');
},
complete: function() {
$(self.maskEl).hide();
}
});
};
and on the index.html page:
var feedUrl = "https://newsline.com/feed/";
$(function() {
var feed = new Feed({
url: feedUrl
});
if (monaca.isIOS) {
$('.toolbar').css('margin-top', '20px');
$('.button').css('top', '20px');
}
$('.button').click(function() {
console.log('Reload.');
feed.load();
});
feed.load();
});
Any help would be appreciated. I am thinking that it has to do with the actual parsing of the xml in feed-reader.js but am not entirely sure.
Thanks!
Update:
I got the url to work as intended, but am now having issues when I try to go back to the home page after clicking an article on the feed (it won't reload the rss feed). The code is the same. For example, here are some screenshots: Image Screenshots
Basically, the feed will load on the home page but if a link is clicked and the user goes to the page and then clicks the back arrow (shown in the screenshots), it comes up with the error message "Failed to load RSS". Is it a jQuery issue where the page isn't grabbing the results again? I have it set to execute once the DOM is ready, so I'm at a loss at why it wouldn't load the feed again if the user goes back to the home page.
Again, any help would be appreciated.
Upvotes: 0
Views: 872
Reputation: 38247
Sounds like a caching issue. If so, PhoneGap disable caching might help you. You need a plugin, which you install as
phonegap local plugin add https://github.com/moderna/cordova-plugin-cache.git
and use by
document.addEventListener('deviceready', onDeviceReady); function onDeviceReady() { var success = function(status) { alert('Message: ' + status); } var error = function(status) { alert('Error: ' + status); } window.cache.clear( success, error ); }
Upvotes: 1