$.Deferred chains

$.Deferred chains

Hi all!

I'm excited about jQuery has implemented Deferred! But I can't find very important functionality - deferred chains. Yes, there is $.when(...) method. But it works only once and then you can't add async call to chain.

I'm looking for something like this:
  1. $.get('/ajax/1/') 
    .done(function(){
    console.log('ajax 1 success'); // first ajax scope
    })
    .then(function(){
    return $.get('/ajax/2/'); // but if we're returning promise ...
    })
    .done(function(){
    console.log('ajax 2 success'); // ... scope changes
    })









Or another approach - to implement $.Deferred().when(...):
  1. $.get('/ajax/1/')
    .done(...)
    .fail(...)
    .when(
    function(){
    return $.get('/ajax/2/');
    },
    function(){
    var d = $.Deferred();
    $('#id').fadeOut(d.resolve);
    return d.promise();
    }
    )
    .done(...)
    .fail(...)














Or maybe there IS already such functionality and I just haven't found it?