0

I have the following code:

(saveData())
.pipe(function(data){return sendhandovermail($('#editperson_id').val());})
.pipe(function(data){setHistory(_eciId,'4','12',true);})
.pipe(function(data){window.location.href = 'input.cfm?m=4&id=45';})
.fail(function(data){$('##msgDialogDetail').html("Error while saving. Please contact bla@blup.com");});

The code works (no errors) but... I was told .pipe() method will do all ajax calls one after the other. IF A returns, B will start. Though when I run it, it's not the case. Am I understanding it wrong, or how should I write this chain to have it execute one after the other?

PoeHaH
  • 1,936
  • 3
  • 28
  • 52

1 Answers1

0

how should I write this chain to have it execute one after the other?

you should return a promise in pre pipe and the later will run according the promise that pre pipe returned.

like this:

var posting = $.post('/step1', data1)
            .pipe(function () {
                return $.post('/step2', data2);
            })
            .pipe(function () {
                return $.post('/step3', data3);
            });

we should use then function instead of pipe in 1.8+ jQuery.

JackChouMine
  • 947
  • 8
  • 22