I've been trying to figure out why I get random feed results at times when 
pulling RSS feeds via Google Feeds API and my HTML5/Javascript mobile app. 
You can see the behavior by going to http://m.wels.net/#singleAudioDevotion 
and clicking the "Refresh" button at the bottom of the screen. Sometimes it 
pulls up the latest feed, sometimes random previous feeds. Here is the 
relevant code I'm using:

Javascript: 
var fake = 1 + Math.floor(Math.random() * 1000);

google.load("feeds", "1");

function popAudioPage(feedURL2, currentId, pageTarget2){
popAudioPagePosts(feedURL2, currentId, function(out) {
var $page = $(pageTarget2),
 // Get the content area element for the page.
$content = $page.children( ":jqmData(role=content)" );
$content.html( out );

$page.page();

// Now call changePage() and tell it to switch to
// the page we just modified.
//$.mobile.changePage($page,{transition: 'slide'});
});
}

//Grab tapped audio feed using Google API and write it to callback variable
function popAudioPagePosts(feedurl2, currentId, callback){
  var feed = new google.feeds.Feed(feedurl2);
  feed.setNumEntries(1);
  var output1 = "";
  feed.load(function(result) {
  if (!result.error) { 

  var entry = result.feed.entries[currentId];
  var mediaGroups = 
result.feed.entries[currentId].mediaGroups[0].contents[0];
  var stripContentSnippet = entry.contentSnippet.replace(/[^a-zA-Z 
0-9.:-]+/g,'');
  var stripaContentSnippet = 
stripContentSnippet.replace('lt--pagingfilter--gt','');

  var longUrl = entry.link;
  
  // Create a page for feed item
output1 = "<h3>";
output1 += entry.title;
output1 += "</h3>";
output1 += '<div align="center"><audio controls src="';
output1 += mediaGroups.url;
output1 += '" preload="auto">Audio player is not supported on your 
device.</audio></div><br>';
output1 += '<div align="center">OR use your device\'s local 
player:</div><br>';
output1 += '<div align="center"><a href="';
output1 += mediaGroups.url;
output1 += '" data-role="button" data-inline="true">Local Player</a></div>';
var endOfSlice = entry.content.indexOf("Listen now");
  var sliceOfContent = entry.content.slice(0,endOfSlice);
output1 += '<h4>Description:</h4>';
output1 += sliceOfContent;
output1 += '</div>';
output1 += '<div align="center"><a href="#share" data-transition="pop" 
data-rel="dialog"><img src="images/81x32share.png"></a>';
output1 += ' &nbsp;&nbsp;<a href="';
output1 += entry.link;
output1 += '"><img src="images/readonwelsdotnet.png"></a></div>';
shortenThatURL(longUrl, entry.title);
 } // end of if statement
callback(output1);
}); // end feed.load (function(result)
} //End listAudioPagePosts function

HTML:
<!--Display single Audio Devotion Page-->
<div data-role="page" id="singleAudioDevotion" data-theme="c" 
data-add-back-btn="true">
  <div data-role="header">
    <div align="center"><img class="welsHeaderImage" 
src="images/welsmobile540x113.png" /></div>
    <a href="#home" data-icon="home" class="ui-btn-right">Home</a>
  </div>
   <div data-role="navbar">
<ul>
<li><a href="#singleAudioDevotion" class="ui-btn-active 
ui-state-persist">Current</a></li>
<li><a href="#listAudioDevotions" id="archiveAudioDevotion" 
class="listTap">Archive</a></li>
</ul>
</div>
  <div data-role="content"></div>
  
  <div data-role="footer" data-position="fixed"> 
<div data-role="navbar">
<ul>
<li><a href="#" onClick="document.location.reload(true)" 
rel="external">Refresh</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</div>

<script type="text/javascript">
popAudioPage("http://feeds.feedburner.com/welsstreamsdailydevotions?fake="+fake,
 
0, "#singleAudioDevotion");
</script>

-- 
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
To view this message on the web, visit
https://groups.google.com/d/msg/google-ajax-search-api/-/DGPpM3089IgJ
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en

Reply via email to