Hello there,
I am having a hard time getting something to work and I am hoping there is someone here who can point me into the right direction.
I basically have two functions. Let’s say function A and function B. Function B contains a chained Promise and returns a Promise that function A processes and produces an outcome. Here is my code:
function A {
B().
then(function(data) {
// This is empty, and is not called. Not sure why??
console.log(data);
});
}
function B {
var promise_1 = function() {
return new Promise(function(resolve, reject) {
// Ajax call here
resolve(data);
});
}
var promise_2 = function(data) {
return new Promise(function(resolve, reject) {
// Another Ajax call here that depends on the data returned by Promise 1 above
resolve(data);
});
}
return promise_1
.then(function(data) {
return promise_2(data);
})
}
I hope the code makes sense. Please let me know what I am doing wrong. I thank you!