Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jquery 1

Status
Not open for further replies.

JamesGMills

Programmer
Aug 15, 2005
157
0
0
GB
Do people use frameworks on here?

I have recently started to get into jquery and have a question if anyone is able to answer it... I did search for a jquery forum/section but I could not find one...


If I have this:

$(function() {

$.ajax({
url: "pages/twitter.php",
cache: false,
success: function(html){
$("#twitter_content").append(html);
}
});


});

How can I make this run every 10 sections without page refresh?

Cheers,

James

------------------------
 
Something like this:

Code:
$(document).everyTime(500, function(count) {
	$.getJSON('pages/twitter.php', function(html) {
		$('#twitter_content').append(html);
	});
}, 0, true);

You might need to tweak params 2 + 3 for your needs, but it's all well documented.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
P.S that was a quick copy/paste so you'd need to change the time delay, and can possibly merge the everyTime in with something else and remove the first line...

Again, check the 'everyTime' docs for more.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
AFAIK everyTime is not a native jQuery function but is available as a plugin.

Alternatively you could roll your own timer script.

I'm also wondering whether you could use the built in timing/callback features of jQuery's native animation functions (such as fadeIn, fadeOut, animate etc).

Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
It looks like a good plugin though. Quite useful!

For the record the Prototype framework has the rather useful PeriodicalExecutor method which is very handy.

I still prefer jQuery though. :)

Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
I think I have that... I think I found it...

Is it the jquery.timers.js

I still cannot get it to work...!?

$(function() {

$.ajax({
url: "pages/lastfm.php",
cache: false,
success: function(html){
$("#lastfm_content").append(html);
}
});


});

I am guessing that I cannot use the $.ajax with this kind of thing?

Should you put everything in the $(function() { }); bit?

Cheers



------------------------
 
You should have something like this

Code:
<script type="text/javascript" charset="utf-8">
		$(document).everyTime(5000,function(){
			$.ajax({
			      url: "twitter.php",
			      cache: false,
			      success: function(html){
			        $("#twitter_content").html(html);
			      }
			});
		},0,true);
	</script>

That is saying to run the ajax call every 5000 milliseconds.

What happens in the ajax call is up to you though.
The above code works for me but my twitter.php page is simply loading the contents of


So what is being shown on the page is raw json data, it isn't parsed in any way.

In what way is it not working?
What are you expecting to happen?

Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Then you have not included the everyTime plugin.

Take a look here: (I've been fiddling around with parsing the JSON data from a twitter search. No PHP script this time so if you view source you will see exactly what is going on).


Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
I have no idea where I got my jquery.timers.js from but I copied the source from yours and uploaded that and it is working a treat!

Thanks for sticking with me!

Now to play a little more with some transactions and stuff :)

Thanks

------------------------
 
So the next little problem I have with this is it does not actually load anything until the first run which is after 10 seconds...

Is there a way to run/load on page load and then set it to repeat every 10 seconds?

Cheers

James

------------------------
 
Why not break out the AJAX into a function, to save repeating the code, then call that function 'on ready' as well?

Something like:

Code:
function doAjax() {
	$.ajax({
		url: 'twitter.php',
		cache: false,
		success: function(html){
			$('#twitter_content').html(html);
		}
	});
}

$(document).everyTime(5000, doAjax, 0, true);

$(document).ready(function() {
	doAjax();
});

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
What I am going to try and do next is only get anything new... and then somehow animate that into the page... So everything that was already there scrolls down and then teh new item/items flash in...

I am guessing that this is going to take a little more php and something to do with time... in the page that I am getting the content from...

Cheers again for the kick start :)

------------------------
 
Yep, more PHP. Although you might be able to do it with Javascript by looking at the JSON returned.

Get the tweets then split the returned data up into individual tweets. Compare the time on them with the time of the last one you are displaying and feed those that are newer to your page.

The animation bit is trivial with jQuery :)

Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top