I'm struggling to grasp promises completely even after reviewing https://gist.github.com/domenic/3889970. I am trying to retrieve the response from axios within a sweetalert confirmation dialog result.
Here is my current code:
axios
.post("/posts", this.formData)
.then(response => {
if (typeof response.data.callback !== "undefined") {
toastr.info("Created");
swal.fire({
title: "Success!",
text: "you created new post",
type: "success",
showConfirmButton: true,
confirmButtonText: "Close this",
allowOutsideClick: false
}).then(result => {
if (result.value) {
window.location.replace(response.data.callback);
}
});;
} else {
toastr.error("Can't process this request");
}
this.formLoading = false;
})
The response variable returns as undefined, indicating that there might be a misunderstanding in how scopes function in JavaScript.