Search code examples
javascriptjquerypipejquery-callbackchain

Chain pipes at jQuery


I'm using jQuery v1.7, so I'm not able to use then. I need to make several nested ajax calls and I want to rid off nested callback calls. I found that at version 1.7 i can use pipe method. But after googling I'm not sure if I'm using it correctly. I have code which looks like this:

step1().pipe(step2, fail).pipe(step3, fail).done(step4, fail)

What I'm trying to do is to pass async call results from step1 to step2 and so on or call fail function in case of error. Finally I call done method.

Signature of step2 is:

function step2(data) {
    ...
}

I omit 2 extra params as they are not necessary for me.


Solution

  • After several tests I can see that it works:

    step1().pipe(step2, fail).pipe(step3, fail).done(step4, fail)
    

    for jQuery v1.7