Click to See Complete Forum and Search --> : Jquery / JSON question. Urgent - $$ for answer.
FINIF
04-14-2010, 09:39 AM
What jquery and json set up is used on http://www.stocktwits.com/streams/all/?
When a new tweet is posted it is automatically updated in the stream and scrolls down. I know a little ajax and jquery, and have looked through the all.js that they are using to do this, but is it a premade script and if so where can I find something similar?
Dissecting the site example sure you gave is a lot of work… but to accomplish the same functionality is not hard.
1. create a PHP script that checks the DB for a “new” entry
2. run an ajax call to that php page:
$.post("db.php", { action: "getNew" },
function(data){
if (data.error) {
//this is if the php returns an error
} else {
//this is if the php returns a new "element"
}
},
"json");
3.once you have the new information built it into a DIV (a bunch of different ways to do this)
4. and now just prepend the div to your main container:
$("#container").prepend(NEW DIV OBJECT);
set that in a function and have it run recursively (with a delay) so not to kill your server & that's it!
-aPeg
FINIF
04-14-2010, 01:10 PM
Yea I've done some simple stuff with reading a JSON file and displaying it, but I'm more interested in the scrolling effect that stocktwits use, where the page doesnt completely refresh, just slides in the newest tweet.
Ya, the code above will accomplish just that.
All you have to do is set display:none on the prepend'ed div(object) then once in place give it a ".slideDown("slow");" and that will give you the effect you're looking for.