homepage Welcome to WebmasterWorld Guest from 54.211.219.68
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
jQuery. callback problem
ctoz

5+ Year Member



 
Msg#: 4261015 posted 6:50 am on Feb 1, 2011 (gmt 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?

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4261015 posted 1:35 pm on Feb 1, 2011 (gmt 0)

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();
});

ctoz

5+ Year Member



 
Msg#: 4261015 posted 9:43 pm on Feb 1, 2011 (gmt 0)

Thanks ! haven't tested yet, but I can see the logic now.

ctoz

5+ Year Member



 
Msg#: 4261015 posted 1:11 am on Feb 3, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved