views:

70

answers:

3

to clarify you know when your on twitter and you get an update telling you have 2 new tweets, i got the ajax referesh page bit sorted but how do i catch the new update and count them!! if i make sense sorry!!

help will be appreciated

cheers!

kindest regards Solomon saleh

A: 

You just have to crate a server side page that return to you the amount of new updates since last reload. And using jQuery (or "regular" JS) just get an AJAX call to this page and use it's response to show to the user how many update he/she got

IgalSt
thank you very much for answering this question, i understand your point, so basically the steps are are:1.to referesh the page using ajax2.see how many updates thier have been after the refresh by making an ajax call.3. then displaying the number of updates!!thanks again
getaway
+3  A: 

The way twitter do it is basically:

  • Have a regular AJAX call to a server-side script that returns the number of new tweets
  • When this number is greater than 0, the "N new tweets" bar is shown
  • Clicking this bar loads the new tweets via another ajax call

One way of catching how many updates there are is to keep track of the last tweet id shown on the user's page (each tweet has a unique id). So, when the page is loaded, the max(tweet id) is, say, 100. Your ajax call to check for updates will be something like:

/check_updates.php?last_seen=100

The check_updates.php script then basically checks the DB for latest tweets for the logged in user where id > 100. Similarly, when the user clicks "Show tweets", the url called will be something along the lines of:

/show_updates.php?last_seen=100

This will mean that show_updates.php only returns tweets that haven't been seen before, keeping response times to a minimum.

The examples above send the id of the last tweet back to the server for comparison, but it could equally be done via the current timestamp. The server-side calculations would essentially be the same (look for tweets since time: X rather than tweet id: y) but it has the benefit of the client side not having to keep track of the last tweet id loaded.

ConroyP
yes thank you very much!!! i get it now,cheers big ears!!
getaway
A: 

You need to send server the information about the last tweet number or some kind of serial number for it to check with twitter (for ex: the last updated time of tweet) or to check from its own list of tweets to identify what tweets to respond back to the client with.

This is how twitter and friendfeed.com sites deal with to enhance user experience on their sites.

You could try checking out the PUSH mechanism on HTTP or sites like pusherapp.com to push your data to the users of your site.

Sairam Kunala