I am trying get the status of the POST request outside of save_function
. I am posting this dummy request to Reddit.
save_function()
always will get the status POST request.
How should I structure my request?
// how can I use always here?
save_function().always(reason => {
// here I am trying to access the post call here
console.log(reason);
})
save_function().then(data => {
console.log("done");
});
function test() {
return $.getJSON("https://www.reddit.com/r/gifs/.json");
}
function save_function() {
let myFirstPromise = new Promise((resolve, reject) => {
if (true) {
test().done(data => {
resolve(data);
})
} else {
resolve({
test: "test"
});
}
});
return myFirstPromise.then((data) => {
console.log(data);
// how do i access this ajax call like caller_function.always()
return $.ajax({
method: "POST",
url: "https://www.reddit.com/r/gifs/.json", //dummy json call
data: {
"test": data.test
}
})
.done(test => {
console.log(test);
})
.fail(reason => {
console.warn(reason);
})
});
}