开发者

problem retrieving data in sinatra when behind a firewall

In my Sinatra app, I'm displaying a continuously updating list of random tweets on my front page: (the tweets aren't real-time, they're just a list of tweets I have stored in a MongoDB databas开发者_运维知识库e on MongoHQ)

:javascript
  function addTweet() {
    $.get("/tweet", function(data) {
      $("table tr#header:first").after(data);
    });  
    setTimeout(addTweet, 2000);
  }

  $(function() {
    setTimeout(addTweet, 2000);
  });

The /tweet page simply gets a random tweet from the database and displays it as a row:

get '/tweet' do  
  @tweet = coll.find().limit(-1).skip(rand(coll.count())).first()['text'] # get a random tweet
  haml :tweet, :layout => false
end

I've deployed the app on Heroku, and it works fine when I access it at home. However, when I access the app at work (from the same laptop and browser as at home), it simply displays the same tweet over and over again on the front page (but going to "/tweet" correctly displays random tweets each time). Any ideas on what the problem is? Is my javascript update call not working for some reason because I'm behind a firewall (but the problem isn't that only a single row gets displayed and then the updating stops, the problem is that the list keeps adding the same tweet over and over again to the list)?


Sounds like a caching issue. Try disabling caching explicitely:

$.ajax({
    method: 'GET',
    url: '/tweet',
    cache: false,
    success: function(data) {
        $("table tr#header:first").after(data);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜