-1

I am confused between the difference between

   var getPromise=$.get('/query'),
       postPromise = getPromise.done(function(data){ 
              return $.post('/search',data); 
       });

and

var getPromise = $.get('/query'); 
var postPromise = getPromise.pipe(function(data){ 
    return $.post('/search',data); 
});

Can anyone explain me?

techfoobar
  • 65,616
  • 14
  • 114
  • 135
Nur Rony
  • 7,823
  • 7
  • 38
  • 45
  • If this is the whole code, then there is no difference. Otherwise, you might want to read the documentation about `.done` and `.pipe`: http://api.jquery.com/deferred.done/, http://api.jquery.com/deferred.pipe/. – Felix Kling Jun 02 '13 at 13:23
  • `pipe` is a deferred command which returns a new promise that filters the status and values of a deferred through a function. This is replaced by the `then` method as of jquery 1.8. – karthikr Jun 02 '13 at 13:24
  • 1
    Maybe this helps you as well: [When should I use jQuery deferred's “then” method and when should I use the “pipe” method?](http://stackoverflow.com/q/9583783/218196). – Felix Kling Jun 02 '13 at 13:27
  • @FelixKling thanks for your link. i am reading it right away. can anyone explain me why this question is down voted? i found it confusing so i posted it. – Nur Rony Jun 02 '13 at 13:31

1 Answers1

0

In the first case postPromise === getPromise. .done returns the same deferred object.

.pipe or .then creates a new deferred instance.

claustrofob
  • 5,448
  • 2
  • 19
  • 22