Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: open

Message Too Old, No Replies

jQuery. callback problem

     
6:50 am on Feb 1, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 4, 2007
posts:112
votes: 0


I have a page where currently there's jQuery 'load' function followed by a regular js setTimeout('function()', delay): which works ok: they're called with "onload".

But it's a gamble on the time it takes to do the 'load', and there'll be a lot of other similar calls: it'd be better if it could be done as a callback, but I've not been able to get the syntax right, although it looks like it should be straightforward.

The test is here:
[www-personal.usyd.edu.au ]

wait six seconds, mouseover any of the six-line figures, you should get a number underneath; click, and you should get a color change, and scrollable text on the left.

The functions are in the js file,
[www-personal.usyd.edu.au ]at lines 43 and 58.

Can anyone help sort it out?
1:35 pm on Feb 1, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


Here's what you have now:

$('#allhex').load('loadem/'+ filename + '.htm');
setTimeout('onD(\'allhex\')',800);


To make the onD call happen as a callback of the load, you would change that to this:



$('#allhex').load('loadem/'+ filename + '.htm', function () {
onD('allhex');
});


Then to add the doWen call to the callback:



$('#allhex').load('loadem/'+ filename + '.htm', function () {
onD('allhex');
doWen();
});
9:43 pm on Feb 1, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 4, 2007
posts:112
votes: 0


Thanks ! haven't tested yet, but I can see the logic now.
1:11 am on Feb 3, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 4, 2007
posts:112
votes: 0


Looking at the solution proposed, I eventually saw that I had too many functions going: went back to the jQuery site and followed instructions for a simple callback, without parameters:

function loadWen() {
$('#allhex').load('loadem/hexWen.htm', doWen);
}

which actually does the business. The pause between the onclick color-change and the appearance of the text is handled by a separate function: so there's no need to hide and then show the text div; and even less need to make that part of a callback.

I'll use different versions of this simple callback to load different sets on the right, linking to different text on the left.

Sometimes just setting the problem out helps. Thanks again.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members