1

I'm using some deferred functions with the .done so, I'm having something like that:

askTime(number).done(formatTime).done(function(html){
   times += html;
});

But although formatTime returns data, the html var has the data returned by askTime.

I don't know where if the problem. formatTime receives a data variable which is returned by askTime but if I put:

askTime(number).done(formatTime(data)).done(function(html)

It says that data isn't defined.

Antonio Laguna
  • 8,137
  • 7
  • 31
  • 68

1 Answers1

2

To chain deferred methods, you need to invoke .pipe().

Have a look: http://api.jquery.com/deferred.pipe/

jAndy
  • 212,463
  • 51
  • 293
  • 348
  • I'm having a look but unable to understand correctly. Examples given are a bit hard or unclear (for me at least) – Antonio Laguna Dec 02 '11 at 13:47
  • @AntonioLaguna Just try ".pipe()" instead of the first ".done()" in your code. – Pointy Dec 02 '11 at 14:00
  • I picked up the final code from here http://stackoverflow.com/questions/5921283/understanding-jquery-deferred-pipe and works and seems to understandable to me but this is not exactly what comes in the docs. Could you give me more light please? – Antonio Laguna Dec 02 '11 at 14:02
  • Thanks again @jAndy you seem to be a master of the deferred! – Antonio Laguna Dec 02 '11 at 14:04