I am struggling to chain the callback with pipes using deferred. It seems to work just fine but in the callback2, it brings me data from callback1. Here is how the code looks like:
var getCall1 = function() {
return $.ajax(url, {
type: "GET",
data: { },
contentType: "application/json",
dataType: "json"
});
}
var getCall2 = function () {
return $.ajax(url, {
type: "GET",
data: {},
contentType: "application/json",
dataType: "json"
});
}
var callback1 = function (data)
{
alert('call 1 completed');
};
var callback2 = function (data)
{
alert('call 2 completed');
};
$.when(getCall1()).done(callBack1).pipe(getCall2()).done(callBack2);
What am i missing here?
--Edit--
If i break them in to two deferred calls, it works but then whats the use of chaining and pipe?
$.when(getCall1()).done(callBack1);
$.when(getCall2()).done(callBack2);
--Correct way to do this--
var getCall1 = function() {
return $.ajax(url, {
type: "GET",
data: { },
contentType: "application/json",
dataType: "json"
});
}.pipe(function (d){return d});
var getCall2 = function () {
return $.ajax(url, {
type: "GET",
data: {},
contentType: "application/json",
dataType: "json"
});
}.pipe(function (d){return d});
var callback1 = function (data)
{
alert('call 1 completed');
};
var callback2 = function (data)
{
alert('call 2 completed');
};
$.when(getCall1, getCall2).done(function(d1, d2){
callback1(d1);
callback2(d2);
});